当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.GOPATH方法代码示例

本文整理汇总了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
}
开发者ID:jiakuan,项目名称:livedev,代码行数:54,代码来源:server.go

示例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
}
开发者ID:qrtz,项目名称:livedev,代码行数:63,代码来源:server.go


注:本文中的go/build.Context.GOPATH方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。