本文整理汇总了Golang中go/build.Context.GOPATH方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GOPATH方法的具体用法?Golang Context.GOPATH怎么用?Golang Context.GOPATH使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/build.Context
的用法示例。
在下文中一共展示了Context.GOPATH方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewServer
func NewServer(context build.Context, s ServerConf) (*Server, error) {
var (
srv = new(Server)
ignore *regexp.Regexp
paths []string
)
if len(s.Resources.Paths) > 0 {
for _, s := range s.Resources.Paths {
if p := strings.TrimSpace(s); len(p) > 0 {
paths = append(paths, p)
}
}
if len(paths) > 0 {
if s := strings.TrimSpace(s.Resources.Ignore); len(s) > 0 {
if pattern, err := regexp.Compile(s); err == nil {
ignore = pattern
} else {
return nil, fmt.Errorf(`Fatal error: Invalid pattern "%s" : %v`, s, err)
}
}
srv.resources = &Resource{ignore, paths}
}
}
srv.target = strings.TrimSpace(s.Target)
srv.targetDir = filepath.Dir(s.Target)
srv.bin = strings.TrimSpace(s.Bin)
srv.builder = s.Builder
if !hasPrefix(srv.target, filepath.SplitList(context.GOPATH)) {
//Target is not in the $GOPATH
//Try to guess the import root(workspace) from the path
roots := ImportRoots(srv.target)
if len(roots) > 0 {
context.GOPATH = strings.Join(append(roots, context.GOPATH), string(filepath.ListSeparator))
}
}
srv.context = context
if len(srv.builder) == 0 {
cmd := filepath.Join(context.GOROOT, "bin", "go")
srv.builder = append(srv.builder, cmd, "build", "-o", srv.bin)
}
srv.port = s.Port
srv.startup = s.Startup
srv.host = s.Host
return srv, nil
}
示例2: newServer
func newServer(context build.Context, conf serverConfig, proxyPort int, w *watcher.Watcher) (*Server, error) {
var err error
srv := new(Server)
srv.conf = conf
srv.proxyPort = proxyPort
srv.resources, err = newResource(conf.Resources.Paths, conf.Resources.Ignore)
if err != nil {
return nil, err
}
srv.assets, err = newResource(conf.Assets.Paths, conf.Assets.Ignore)
if err != nil {
return nil, err
}
srv.startupTimeout = conf.StartupTimeout
srv.target = strings.TrimSpace(conf.Target)
srv.targetDir = filepath.Dir(conf.Target)
srv.bin = strings.TrimSpace(conf.Bin)
srv.builder = conf.Builder
if !hasPrefix(srv.target, filepath.SplitList(context.GOPATH)) {
// Target is not in the $GOPATH
// Try to guess the import root(workspace) from the path
roots := importRoots(srv.target)
if len(roots) > 0 {
context.GOPATH = strings.Join(append(roots, context.GOPATH), string(filepath.ListSeparator))
}
}
srv.context = context
if len(srv.builder) == 0 {
gobin := "go"
if len(context.GOROOT) > 0 && fileExists(context.GOROOT) {
gobin = filepath.Join(context.GOROOT, "bin", gobin)
}
srv.builder = append(srv.builder, gobin, "build", "-o", srv.bin)
}
srv.watcher = w
srv.watcherEvents = make(chan watcher.Event, 1)
srv.ready = make(chan error, 1)
srv.busy = make(chan bool, 1)
srv.stopped = make(chan bool, 1)
srv.started = make(chan bool, 1)
srv.done = make(chan error, 1)
srv.exit = make(chan bool, 1)
srv.updateListeners = newUpdateListeners()
srv.port = conf.Port
srv.startup = conf.Startup
srv.host = conf.Host
srv.stdout = logger.NewLogWriter(os.Stdout, srv.host+"> ", log.LstdFlags)
srv.stderr = new(logger.BufferedLogWriter)
return srv, nil
}