// ParseAPI parses general api info for gived searchDir and mainAPIFile
975747
func (parser *Parser) ParseAPI(searchDir string, mainAPIFile string) error {
	Println("Generate general API Info")
	if err := parser.getAllGoFileInfo(searchDir); err != nil {
		return err
	}
	parser.ParseGeneralAPIInfo(path.Join(searchDir, mainAPIFile))

	for _, astFile := range parser.files {
		parser.ParseType(astFile)
	}

	for fileName, astFile := range parser.files {
		if err := parser.ParseRouterAPIInfo(fileName, astFile); err != nil {
			return err
		}
	}

	parser.ParseDefinitions()

	return nil
}
4034
func (g *GoParser) parsePackageDir(directory string) {
	pkg, err := build.Default.ImportDir(directory, 0)
	if err != nil {
		log.Fatalf("cannot process directory %s: %s", directory, err)
	}
	var names []string
	names = append(names, pkg.GoFiles...)
	//names = append(names, pkg.CgoFiles...)
	//names = append(names, pkg.SFiles...)
	names = prefixDirectory(directory, names)
	g.parsePackage(directory, names, nil)
}
793099
func ServeAPI(host, basePath string, schemes []string) (err error) {
	// swagger:operation GET /pets pets getPet
	//
	// List all pets
	//
	// ---
	// parameters:
	//   - name: limit
	//     in: query
	//     description: How many items to return at one time (max 100)
	//     required: false
	//     type: integer
	//     format: int32
	// consumes:
	//   - "application/json"
	//   - "application/xml"
	// produces:
	//   - "application/xml"
	//   - "application/json"
	// responses:
	//   "200":
	//     description: An paged array of pets
	//     headers:
	//       x-next:
	//         type: string
	//         description: A link to the next page of responses
	//     schema:
	//       type: array
	//       items:
	//         schema:
	//           type: object
	//           required:
	//             - id
	//             - name
	//           properties:
	//             id:
	//               type: integer
	//               format: int64
	//             name:
	//               type: string
	//   default:
	//     description: unexpected error
	//     schema:
	//       type: object
	//       required:
	//         - code
	//         - message
	//       properties:
	//         code:
	//           type: integer
	//           format: int32
	//         message:
	//           type: string
	// security:
	//   -
	//     petstore_auth:
	//       - "write:pets"
	//       - "read:pets"
	mountItem("GET", basePath+"/pets", nil)

	// swagger:operation PUT /pets/{id} pets updatePet
	//
	// Updates the details for a pet.
	//
	// Some long explanation,
	// spanning over multipele lines,
	// AKA the description.
	//
	// ---
	// consumes:
	//   - "application/json"
	//   - "application/xml"
	// produces:
	//   - "application/xml"
	//   - "application/json"
	// parameters:
	//   -
	//     in: "body"
	//     name: "body"
	//     description: "Pet object that needs to be added to the store"
	//     required: true
	//     schema:
	//       type: object
	//       required:
	//       - name
	//       properties:
	//         name:
	//           type: string
	//         age:
	//           type: integer
	//           format: int32
	//           minimum: 0
	//   -
	//     in: "path"
	//     name: "id"
	//     description: "Pet object that needs to be added to the store"
	//     required: true
	//     schema:
	//       type: string
	//       pattern: "[A-Z]{3}-[0-9]{3}"
	// responses:
	//   400:
	//     description: "Invalid ID supplied"
	//   404:
	//     description: "Pet not found"
	//   405:
	//     description: "Validation exception"
	// security:
	//   -
	//     petstore_auth:
	//       - "write:pets"
	//       - "read:pets"
	mountItem("PUT", basePath+"/pets/{id}", nil)

	// swagger:operation GET /v1/events Events getEvents
	//
	// Events
	//
	// Mitigation Events
	//
	// ---
	// consumes:
	//   - "application/json"
	//   - "application/xml"
	// produces:
	//   - "application/xml"
	//   - "application/json"
	// parameters:
	// - name: running
	//   in: query
	//   description: (boolean) Filters
	//   required: false
	//   type: boolean
	//
	// responses:
	//  '200':
	//    description: '200'
	//    schema:
	//	    "$ref": "#/definitions/ListResponse"
	//  '400':
	//    description: '400'
	//    schema:
	//      "$ref": "#/definitions/ErrorResponse"
	// security:
	//   -
	//     petstore_auth:
	//       - "write:pets"
	//       - "read:pets"
	mountItem("GET", basePath+"/events", nil)

	// no errors to return, all good
	return
}
870604
func (parser *Parser) ParseGeneralAPIInfo(mainAPIFile string) error {
	fileSet := token.NewFileSet()
	fileTree, err := goparser.ParseFile(fileSet, mainAPIFile, nil, goparser.ParseComments)
	if err != nil {
		return errors.Wrap(err, "cannot parse soure files")
	}

	parser.swagger.Swagger = "2.0"
	securityMap := map[string]*spec.SecurityScheme{}

	// templated defaults
	parser.swagger.Info.Version = "{{.Version}}"
	parser.swagger.Info.Title = "{{.Title}}"
	parser.swagger.Info.Description = "{{.Description}}"
	parser.swagger.Host = "{{.Host}}"
	parser.swagger.BasePath = "{{.BasePath}}"

	if fileTree.Comments != nil {
		for _, comment := range fileTree.Comments {
			comments := strings.Split(comment.Text(), "\n")
			previousAttribute := ""
			for _, commentLine := range comments {
				attribute := strings.ToLower(strings.Split(commentLine, " ")[0])
				multilineBlock := false
				if previousAttribute == attribute {
					multilineBlock = true
				}
				switch attribute {
				case "@version":
					parser.swagger.Info.Version = strings.TrimSpace(commentLine[len(attribute):])
				case "@title":
					parser.swagger.Info.Title = strings.TrimSpace(commentLine[len(attribute):])
				case "@description":
					if parser.swagger.Info.Description == "{{.Description}}" {
						parser.swagger.Info.Description = strings.TrimSpace(commentLine[len(attribute):])
					} else if multilineBlock {
						parser.swagger.Info.Description += "\n" + strings.TrimSpace(commentLine[len(attribute):])
					}
				case "@termsofservice":
					parser.swagger.Info.TermsOfService = strings.TrimSpace(commentLine[len(attribute):])
				case "@contact.name":
					parser.swagger.Info.Contact.Name = strings.TrimSpace(commentLine[len(attribute):])
				case "@contact.email":
					parser.swagger.Info.Contact.Email = strings.TrimSpace(commentLine[len(attribute):])
				case "@contact.url":
					parser.swagger.Info.Contact.URL = strings.TrimSpace(commentLine[len(attribute):])
				case "@license.name":
					parser.swagger.Info.License.Name = strings.TrimSpace(commentLine[len(attribute):])
				case "@license.url":
					parser.swagger.Info.License.URL = strings.TrimSpace(commentLine[len(attribute):])
				case "@host":
					parser.swagger.Host = strings.TrimSpace(commentLine[len(attribute):])
				case "@basepath":
					parser.swagger.BasePath = strings.TrimSpace(commentLine[len(attribute):])
				case "@schemes":
					parser.swagger.Schemes = getSchemes(commentLine)
				case "@tag.name":
					commentInfo := strings.TrimSpace(commentLine[len(attribute):])
					parser.swagger.Tags = append(parser.swagger.Tags, spec.Tag{
						TagProps: spec.TagProps{
							Name: strings.TrimSpace(commentInfo),
						},
					})
				case "@tag.description":
					commentInfo := strings.TrimSpace(commentLine[len(attribute):])
					tag := parser.swagger.Tags[len(parser.swagger.Tags)-1]
					tag.TagProps.Description = commentInfo
					replaceLastTag(parser.swagger.Tags, tag)
				case "@tag.docs.url":
					commentInfo := strings.TrimSpace(commentLine[len(attribute):])
					tag := parser.swagger.Tags[len(parser.swagger.Tags)-1]
					tag.TagProps.ExternalDocs = &spec.ExternalDocumentation{
						URL: commentInfo,
					}
					replaceLastTag(parser.swagger.Tags, tag)

				case "@tag.docs.description":
					commentInfo := strings.TrimSpace(commentLine[len(attribute):])
					tag := parser.swagger.Tags[len(parser.swagger.Tags)-1]
					if tag.TagProps.ExternalDocs == nil {
						return errors.New("@tag.docs.description needs to come after a @tags.docs.url")
					}
					tag.TagProps.ExternalDocs.Description = commentInfo
					replaceLastTag(parser.swagger.Tags, tag)
				}
				previousAttribute = attribute
			}

			for i := 0; i < len(comments); i++ {
				attribute := strings.ToLower(strings.Split(comments[i], " ")[0])
				switch attribute {
				case "@securitydefinitions.basic":
					securityMap[strings.TrimSpace(comments[i][len(attribute):])] = spec.BasicAuth()
				case "@securitydefinitions.apikey":
					attrMap := map[string]string{}
					for _, v := range comments[i+1:] {
						securityAttr := strings.ToLower(strings.Split(v, " ")[0])
						if securityAttr == "@in" || securityAttr == "@name" {
							attrMap[securityAttr] = strings.TrimSpace(v[len(securityAttr):])
						}
						// next securityDefinitions
						if strings.Index(securityAttr, "@securitydefinitions.") == 0 {
							break
						}
					}
					if len(attrMap) != 2 {
						return errors.New("@securitydefinitions.apikey is @name and @in required")
					}
					securityMap[strings.TrimSpace(comments[i][len(attribute):])] = spec.APIKeyAuth(attrMap["@name"], attrMap["@in"])
				case "@securitydefinitions.oauth2.application":
					attrMap := map[string]string{}
					scopes := map[string]string{}
					for _, v := range comments[i+1:] {
						securityAttr := strings.ToLower(strings.Split(v, " ")[0])
						if securityAttr == "@tokenurl" {
							attrMap[securityAttr] = strings.TrimSpace(v[len(securityAttr):])
						} else {
							isExists, err := isExistsScope(securityAttr)
							if err != nil {
								return err
							}
							if isExists {
								scopScheme, err := getScopeScheme(securityAttr)
								if err != nil {
									return err
								}
								scopes[scopScheme] = v[len(securityAttr):]
							}
						}
						// next securityDefinitions
						if strings.Index(securityAttr, "@securitydefinitions.") == 0 {
							break
						}
					}
					if len(attrMap) != 1 {
						return errors.New("@securitydefinitions.oauth2.application is @tokenUrl required")
					}
					securityScheme := spec.OAuth2Application(attrMap["@tokenurl"])
					for scope, description := range scopes {
						securityScheme.AddScope(scope, description)
					}
					securityMap[strings.TrimSpace(comments[i][len(attribute):])] = securityScheme
				case "@securitydefinitions.oauth2.implicit":
					attrMap := map[string]string{}
					scopes := map[string]string{}
					for _, v := range comments[i+1:] {
						securityAttr := strings.ToLower(strings.Split(v, " ")[0])
						if securityAttr == "@authorizationurl" {
							attrMap[securityAttr] = strings.TrimSpace(v[len(securityAttr):])
						} else {
							isExists, err := isExistsScope(securityAttr)
							if err != nil {
								return err
							}
							if isExists {
								scopScheme, err := getScopeScheme(securityAttr)
								if err != nil {
									return err
								}
								scopes[scopScheme] = v[len(securityAttr):]
							}
						}
						// next securityDefinitions
						if strings.Index(securityAttr, "@securitydefinitions.") == 0 {
							break
						}
					}
					if len(attrMap) != 1 {
						return errors.New("@securitydefinitions.oauth2.implicit is @authorizationUrl required")
					}
					securityScheme := spec.OAuth2Implicit(attrMap["@authorizationurl"])
					for scope, description := range scopes {
						securityScheme.AddScope(scope, description)
					}
					securityMap[strings.TrimSpace(comments[i][len(attribute):])] = securityScheme
				case "@securitydefinitions.oauth2.password":
					attrMap := map[string]string{}
					scopes := map[string]string{}
					for _, v := range comments[i+1:] {
						securityAttr := strings.ToLower(strings.Split(v, " ")[0])
						if securityAttr == "@tokenurl" {
							attrMap[securityAttr] = strings.TrimSpace(v[len(securityAttr):])
						} else {
							isExists, err := isExistsScope(securityAttr)
							if err != nil {
								return err
							}
							if isExists {
								scopScheme, err := getScopeScheme(securityAttr)
								if err != nil {
									return err
								}
								scopes[scopScheme] = v[len(securityAttr):]
							}
						}
						// next securityDefinitions
						if strings.Index(securityAttr, "@securitydefinitions.") == 0 {
							break
						}
					}
					if len(attrMap) != 1 {
						return errors.New("@securitydefinitions.oauth2.password is @tokenUrl required")
					}
					securityScheme := spec.OAuth2Password(attrMap["@tokenurl"])
					for scope, description := range scopes {
						securityScheme.AddScope(scope, description)
					}
					securityMap[strings.TrimSpace(comments[i][len(attribute):])] = securityScheme
				case "@securitydefinitions.oauth2.accesscode":
					attrMap := map[string]string{}
					scopes := map[string]string{}
					for _, v := range comments[i+1:] {
						securityAttr := strings.ToLower(strings.Split(v, " ")[0])
						if securityAttr == "@tokenurl" || securityAttr == "@authorizationurl" {
							attrMap[securityAttr] = strings.TrimSpace(v[len(securityAttr):])
						} else {
							isExists, err := isExistsScope(securityAttr)
							if err != nil {
								return err
							}
							if isExists {
								scopScheme, err := getScopeScheme(securityAttr)
								if err != nil {
									return err
								}
								scopes[scopScheme] = v[len(securityAttr):]
							}
						}
						// next securityDefinitions
						if strings.Index(securityAttr, "@securitydefinitions.") == 0 {
							break
						}
					}
					if len(attrMap) != 2 {
						return errors.New("@securitydefinitions.oauth2.accessCode is @tokenUrl and @authorizationUrl required")
					}
					securityScheme := spec.OAuth2AccessToken(attrMap["@authorizationurl"], attrMap["@tokenurl"])
					for scope, description := range scopes {
						securityScheme.AddScope(scope, description)
					}
					securityMap[strings.TrimSpace(comments[i][len(attribute):])] = securityScheme
				}
			}
		}
	}
	if len(securityMap) > 0 {
		parser.swagger.SecurityDefinitions = securityMap
	}

	return nil
}
1317112
func ParseFile(filename string) (string, error) {
	bs, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", err
	}
	return Parse(filepath.Base(filename), bs)
}
416577
func parseFile(source string) (*model.Package, error) {
	srcDir, err := filepath.Abs(filepath.Dir(source))
	if err != nil {
		return nil, fmt.Errorf("failed getting source directory: %v", err)
	}

	cfg := &packages.Config{Mode: packages.LoadSyntax, Tests: true}
	pkgs, err := packages.Load(cfg, "file="+source)
	if err != nil {
		return nil, err
	}
	if packages.PrintErrors(pkgs) > 0 || len(pkgs) == 0 {
		return nil, errors.New("loading package failed")
	}

	packageImport := pkgs[0].PkgPath

	// It is illegal to import a _test package.
	packageImport = strings.TrimSuffix(packageImport, "_test")

	fs := token.NewFileSet()
	file, err := parser.ParseFile(fs, source, nil, 0)
	if err != nil {
		return nil, fmt.Errorf("failed parsing source file %v: %v", source, err)
	}

	p := &fileParser{
		fileSet:            fs,
		imports:            make(map[string]string),
		importedInterfaces: make(map[string]map[string]*ast.InterfaceType),
		auxInterfaces:      make(map[string]map[string]*ast.InterfaceType),
		srcDir:             srcDir,
	}

	// Handle -imports.
	dotImports := make(map[string]bool)
	if *imports != "" {
		for _, kv := range strings.Split(*imports, ",") {
			eq := strings.Index(kv, "=")
			k, v := kv[:eq], kv[eq+1:]
			if k == "." {
				// TODO: Catch dupes?
				dotImports[v] = true
			} else {
				// TODO: Catch dupes?
				p.imports[k] = v
			}
		}
	}

	// Handle -aux_files.
	if err := p.parseAuxFiles(*auxFiles); err != nil {
		return nil, err
	}
	p.addAuxInterfacesFromFile(packageImport, file) // this file

	pkg, err := p.parseFile(packageImport, file)
	if err != nil {
		return nil, err
	}
	for path := range dotImports {
		pkg.DotImports = append(pkg.DotImports, path)
	}
	return pkg, nil
}
1180259
func (mo *Mo) ParseFile(f string) {
	// Check if file exists
	info, err := os.Stat(f)
	if err != nil {
		return
	}

	// Check that isn't a directory
	if info.IsDir() {
		return
	}

	// Parse file content
	data, err := ioutil.ReadFile(f)
	if err != nil {
		return
	}

	mo.Parse(data)
}
1313748
func ParseFile(path string) (map[string]map[string]string, error) {
	r, err := os.Open(path)
	if err != nil {
		return nil, errors.Wrapf(err, "ParseFile")
	}
	defer r.Close()
	return Parse(r)
}
1326777
func (c *CmdSimpleFSRead) ParseArgv(ctx *cli.Context) error {
	nargs := len(ctx.Args())
	var err error

	c.bufSize = ctx.Int("buffersize")

	if nargs != 1 {
		return fmt.Errorf("read requires a path argument")
	}

	// TODO: "rev" should be a real int64, need to update the
	// `cli` library for that.
	p, err := makeSimpleFSPathWithArchiveParams(
		ctx.Args()[0], int64(ctx.Int("rev")), ctx.String("time"),
		getRelTime(ctx))
	if err != nil {
		return err
	}

	c.path = p
	return nil
}
746650
func (c *SubnetCommandBase) NewAPI() (SubnetAPI, error) {
	if c.api != nil {
		// Already created.
		return c.api, nil
	}
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}

	// This is tested with a feature test.
	shim := &mvpAPIShim{
		apiState: root,
		facade:   subnets.NewAPI(root),
	}
	return shim, nil
}
831682
func ParseAccept(header http.Header, key string) (specs []AcceptSpec) {
loop:
	for _, s := range header[key] {
		for {
			var spec AcceptSpec
			spec.Value, s = expectTokenSlash(s)
			if spec.Value == "" {
				continue loop
			}
			spec.Q = 1.0
			s = skipSpace(s)
			if strings.HasPrefix(s, ";") {
				s = skipSpace(s[1:])
				for !strings.HasPrefix(s, "q=") && s != "" && !strings.HasPrefix(s, ",") {
					s = skipSpace(s[1:])
				}
				if strings.HasPrefix(s, "q=") {
					spec.Q, s = expectQuality(s[2:])
					if spec.Q < 0.0 {
						continue loop
					}
				}
			}
			specs = append(specs, spec)
			s = skipSpace(s)
			if !strings.HasPrefix(s, ",") {
				continue loop
			}
			s = skipSpace(s[1:])
		}
	}
	return
}
1368665
func HostApi(apiType HostApiType) (*HostApiInfo, error) {
	hosts, err := HostApis()
	if err != nil {
		return nil, err
	}
	i := C.Pa_HostApiTypeIdToHostApiIndex(C.PaHostApiTypeId(apiType))
	if i < 0 {
		return nil, newError(C.PaError(i))
	}
	return hosts[i], nil
}
290177
func (c *CmdSimpleFSQuota) ParseArgv(ctx *cli.Context) error {
	c.git = ctx.Bool("git")
	c.bytes = ctx.Bool("bytes")
	c.archived = ctx.Bool("archived")
	c.json = ctx.Bool("json")

	if len(ctx.String("team")) > 0 {
		teamName, err := keybase1.TeamNameFromString(ctx.String("team"))
		if err != nil {
			return err
		}
		c.teamName = teamName
	}

	return nil
}
682396
func (g *GoParser) parsePackage(directory string, names []string, text interface{}) {
	var files []*File
	var astFiles []*ast.File
	g.Package = new(Package)
	fs := token.NewFileSet()
	for _, name := range names {
		if !strings.HasSuffix(name, ".go") {
			continue
		}
		parsedFile, err := parser.ParseFile(fs, name, text, 0)
		if err != nil {
			log.Fatalf("parsing package: %s: %s", name, err)
		}
		astFiles = append(astFiles, parsedFile)
		files = append(files, &File{
			file: parsedFile,
			pkg:  g.Package,
		})
	}
	if len(astFiles) == 0 {
		log.Fatalf("%s: no buildable Go files", directory)
	}
	g.Package.Name = astFiles[0].Name.Name
	g.Package.files = files
	g.Package.dir = directory
	// Type check the package.
	g.Package.check(fs, astFiles)
}
970720
func (c *CmdSimpleFSCopy) ParseArgv(ctx *cli.Context) error {
	var err error

	c.recurse = ctx.Bool("recursive")
	c.interactive = ctx.Bool("interactive")
	c.force = ctx.Bool("force")

	if c.force && c.interactive {
		return errors.New("force and interactive are incompatible")
	}

	c.src, c.dest, err = parseSrcDestArgs(c.G(), ctx, "cp")

	return err
}
513759
func (c *CmdSimpleFSSyncEnable) ParseArgv(ctx *cli.Context) error {
	if len(ctx.Args()) != 1 {
		return fmt.Errorf("wrong number of arguments")
	}

	p, err := makeSimpleFSPath(ctx.Args()[0])
	if err != nil {
		return err
	}
	c.path = p
	return nil
}
89735
func (p *HttpStartStopProcessor) parseEventUri(uri string) string {

  hostname := ""

  //we first remove the scheme
  if strings.Contains(uri, "://") {
  	uri = strings.Split(uri, "://")[1]
  }

  //and then proceed with extracting the hostname
  hostname = strings.Split(uri, "/")[0]
  hostname = strings.Replace(hostname, ".", "_", -1)
  hostname = strings.Replace(hostname, ":", "_", -1)

	if !(len(hostname) > 0) {
		panic(errors.New("Hostname cannot be extracted from Event uri: " + uri))
	}

	return hostname
}