gosrc

package
v0.0.0-...-dbf91d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 6 Imported by: 0

README

gosrc

gosrc package provide a tool for get go src dir by import path (in this workspace)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoSrc

type GoSrc struct {
	// module名字
	ModuleName       string `json:"module_name"`
	AbsModuleFileDir string
}

GoSrc 负责管理 包引入地址 和 实际文件地址 之间的关系

func NewGoSrcFromModFile

func NewGoSrcFromModFile(modFile string) (*GoSrc, error)

func (*GoSrc) FormatPath

func (s *GoSrc) FormatPath(path string) (fp string, isInProject bool)

FormatPath 会格式化用户在yaml中写的路径为规范路径, 即将相对路径转换为包含module名字的完整路径

func (*GoSrc) GetAbsPath

func (s *GoSrc) GetAbsPath(path string) (absDir string, isInProject bool, err error)

获取文件的绝对路径 e.g.

path: github.com/gopenapi/gopenapi/internal/model, returned: Z:\golang\go_project\gopenapi\internal\model
path: github.com/gopenapi/gopenapi/internal/delivery/http/handler/pet.go, returned: Z:\golang\go_project\gopenapi\internal\delivery\http\handler\pet.go
path: ./internal/delivery/http/handler/pet.go, returned: Z:\golang\go_project\gopenapi\internal\delivery\http\handler\pet.go

return:

isInProject: 是否是本项目的地址

func (*GoSrc) GetPkgPath

func (s *GoSrc) GetPkgPath(absPath string) (pkgPath string, err error)

GetPkgPath 返回相对路径

func (*GoSrc) MustGetAbsPath

func (s *GoSrc) MustGetAbsPath(path string) (absDir string, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL