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


Golang config.Config类代码示例

本文整理汇总了Golang中github.com/ernestokarim/cb/config.Config的典型用法代码示例。如果您正苦于以下问题:Golang Config类的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: prepareDist

func prepareDist(c *config.Config, q *registry.Queue) error {
	dirs := c.GetListRequired("dist.prepare")
	for _, from := range dirs {
		to := "temp"
		if strings.Contains(from, "->") {
			parts := strings.Split(from, "->")
			from = strings.TrimSpace(parts[0])
			to = filepath.Join("temp", strings.TrimSpace(parts[1]))
		}

		if _, err := os.Stat(from); err != nil {
			if os.IsNotExist(err) {
				continue
			}
			return fmt.Errorf("stat failed: %s", err)
		}

		if err := os.MkdirAll(filepath.Dir(to), 0755); err != nil {
			return fmt.Errorf("prepare dir failed (%s): %s", to, err)
		}

		output, err := utils.Exec("cp", []string{"-r", from, to})
		if err != nil {
			fmt.Println(output)
			return fmt.Errorf("copy error: %s", err)
		}
	}
	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:29,代码来源:dist.go

示例2: minignore

func minignore(c *config.Config, q *registry.Queue) error {
	base := filepath.Join("temp", filepath.Base(c.GetRequired("paths.base")))
	lines, err := utils.ReadLines(base)
	if err != nil {
		return fmt.Errorf("read base html failed: %s", err)
	}
	for i, line := range lines {
		if strings.Contains(line, "<!-- min -->") {
			matchs := minRe.FindStringSubmatch(line)
			if matchs == nil {
				return fmt.Errorf("line %d of base, not a correct min format", i+1)
			}
			src := strings.Replace(matchs[1], ".js", ".min.js", -1)
			line = fmt.Sprintf("<script src=\"%s\"></script>\n", src)
		}
		if strings.Contains(line, "<!-- ignore -->") {
			line = ""
		}
		lines[i] = line
	}

	if err := utils.WriteFile(base, strings.Join(lines, "")); err != nil {
		return fmt.Errorf("write file failed: %s", err)
	}

	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:27,代码来源:minignore.go

示例3: push

func push(c *config.Config, q *registry.Queue) error {
	scriptsPath := utils.PackagePath(selfPkg)
	host := c.GetRequired("push")

	// FTP User & password
	user := q.NextTask()
	if user == "" {
		return fmt.Errorf("ftp user required as the first argument")
	}
	q.RemoveNextTask()

	password, err := gopass.GetPass(fmt.Sprintf("Enter \"%s\" password: ", user))
	if err != nil {
		return fmt.Errorf("cannot read password: %s", err)
	}
	if password == "" {
		return fmt.Errorf("ftp password is required")
	}

	// Hash local files
	log.Printf("Hashing local files... ")
	localHashes, err := hashLocalFiles()
	if err != nil {
		return fmt.Errorf("hash local files failed: %s", err)
	}
	log.Printf("Hashing local files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Hash remote files
	log.Printf("Hashing remote files... ")
	remoteHashes, err := retrieveRemoteHashes(scriptsPath, user, password, host)
	if err != nil {
		return fmt.Errorf("retrieve remote hashes failed: %s", err)
	}
	log.Printf("Hashing remote files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	if err := saveLocalHashes(localHashes); err != nil {
		return fmt.Errorf("save local hashes failed: %s", err)
	}

	// Prepare FTP commands
	log.Printf("Preparing FTP commands... ")
	if err := prepareFTPCommands(localHashes, remoteHashes); err != nil {
		return fmt.Errorf("prepare FTP commands failed: %s", err)
	}
	log.Printf("Preparing FTP commands... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Upload files
	log.Printf("Uploading files... ")
	if err := uploadFiles(scriptsPath, user, password, host); err != nil {
		return fmt.Errorf("uploading files failed: %s", err)
	}
	log.Printf("Uploading files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:55,代码来源:push.go

示例4: compilejs

func compilejs(c *config.Config, q *registry.Queue) error {
	base := filepath.Join("temp", filepath.Base(c.GetRequired("paths.base")))
	lines, err := utils.ReadLines(base)
	if err != nil {
		return fmt.Errorf("read base html failed: %s", err)
	}
	for i := 0; i < len(lines); i++ {
		line := lines[i]
		if strings.Contains(line, "<!-- compile") {
			match := tagRe.FindStringSubmatch(line)
			if match == nil {
				return fmt.Errorf("incorrect compile tag, line %d", i)
			}

			start := i
			lines[i] = ""

			files := []string{}
			for !strings.Contains(line, "<!-- endcompile -->") {
				match := scriptRe.FindStringSubmatch(line)
				if match != nil {
					lines[i] = ""
					files = append(files, match[1])
				}

				i++
				if i >= len(lines) {
					return fmt.Errorf("compile js block not closed, line %d", start)
				}
				line = lines[i]
			}
			if len(files) == 0 {
				return fmt.Errorf("no files found to compile %s", match[1])
			}

			if err := compileJs(match[1], files); err != nil {
				return fmt.Errorf("compile js failed: %s", err)
			}
			line = fmt.Sprintf("<script src=\"%s\"></script>\n", match[1])
		}
		lines[i] = line
	}

	if err := utils.WriteFile(base, strings.Join(lines, "")); err != nil {
		return fmt.Errorf("write file failed: %s", err)
	}
	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:48,代码来源:compile.go

示例5: deploy

func deploy(c *config.Config, q *registry.Queue) error {
	parts := strings.Split(q.CurTask, ":")
	base := utils.PackagePath(filepath.Join(selfPkg, parts[1]+".sh"))

	args := []string{
		filepath.Base(c.GetRequired("paths.base")),
	}
	if err := utils.ExecCopyOutput(base, args); err != nil {
		return fmt.Errorf("deploy failed: %s", err)
	}

	if err := organizeResult(c); err != nil {
		return fmt.Errorf("cannot organize result: %s", err)
	}

	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:17,代码来源:deploy.go

示例6: controller

func controller(c *config.Config, q *registry.Queue) error {
	name := q.NextTask()
	if name == "" {
		return fmt.Errorf("first arg should be the name of the controller")
	}
	q.RemoveNextTask()
	if !strings.Contains(name, "Ctrl") {
		name = name + "Ctrl"
	}
	module := q.NextTask()
	if module == "" {
		return fmt.Errorf("second arg should be the module of the controller")
	}
	q.RemoveNextTask()
	route := q.NextTask()
	q.RemoveNextTask()

	data := &controllerData{
		Name:     name,
		Module:   module,
		Route:    route,
		Filename: filepath.Join(strings.Split(module, ".")...),
		AppPath:  c.GetDefault("paths.app", filepath.Join("app", "scripts", "app.js")),
	}
	if err := writeControllerFile(data); err != nil {
		return fmt.Errorf("write controller failed: %s", err)
	}
	if err := writeControllerTestFile(data); err != nil {
		return fmt.Errorf("write controller test failed: %s", err)
	}
	if err := writeControllerViewFile(data); err != nil {
		return fmt.Errorf("write view failed: %s", err)
	}
	if route != "" {
		if err := writeControllerRouteFile(data); err != nil {
			return fmt.Errorf("write route failed: %s", err)
		}
	}

	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:41,代码来源:angular.go

示例7: copyDist

func copyDist(c *config.Config, q *registry.Queue) error {
	dirs := c.GetListRequired("dist.final")

	changes := utils.LoadChanges()
	for i, dir := range dirs {
		if name, ok := changes[dir]; ok {
			dir = name
		}
		dirs[i] = dir
	}

	for _, dir := range dirs {
		from := dir
		to := dir
		if strings.Contains(dir, "->") {
			parts := strings.Split(dir, "->")
			from = strings.TrimSpace(parts[0])
			to = strings.TrimSpace(parts[1])
		}
		origin := filepath.Join("temp", from)
		dest := filepath.Join("dist", to)

		if err := os.MkdirAll(filepath.Dir(dest), 0755); err != nil {
			return fmt.Errorf("prepare dir failed (%s): %s", dir, err)
		}

		if *config.Verbose {
			log.Printf("copy `%s`\n", origin)
		}

		output, err := utils.Exec("cp", []string{"-r", origin, dest})
		if err != nil {
			fmt.Println(output)
			return fmt.Errorf("copy error: %s", err)
		}
	}

	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:39,代码来源:dist.go

示例8: readServeConfig

func readServeConfig(c *config.Config) (*serveConfig, error) {
	sc := &serveConfig{
		base: true,
		url:  c.GetDefault("serve.url", "http://localhost:8080/"),
	}

	method := c.GetDefault("serve.base", "")
	if method != "" && method != "proxy" && method != "cb" {
		return nil, fmt.Errorf("serve.base config must be 'proxy' (default) or 'cb'")
	}
	sc.base = (method == "cb")

	size := c.CountDefault("serve.proxy")
	for i := 0; i < size; i++ {
		pc := proxyConfig{
			host: fmt.Sprintf("%s:%d", c.GetRequired("serve.proxy[%d].host", i), *config.Port),
			url:  c.GetRequired("serve.proxy[%d].url", i),
		}
		sc.proxy = append(sc.proxy, pc)
	}

	return sc, nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:23,代码来源:config.go

示例9: Parse

func Parse(data *config.Config, idx int) []*Validator {
	validators := []*Validator{}

	nvalidators := data.CountDefault("fields[%d].validators", idx)
	for i := 0; i < nvalidators; i++ {
		name := data.GetRequired("fields[%d].validators[%d].name", idx, i)
		value := data.GetDefault("fields[%d].validators[%d].value", "", idx, i)
		msg := data.GetDefault("fields[%d].validators[%d].msg", "", idx, i)
		validator := createValidator(name, value, msg)
		if validator == nil {
			panic("bad validator name: " + name)
		}
		validators = append(validators, validator)
	}

	return validators
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:17,代码来源:parse.go

示例10: build

func build(c *config.Config, q *registry.Queue) error {
	q.AddTasks([]string{
		"update:[email protected]",
		"[email protected]",
		"dist:[email protected]",
		"recess:[email protected]",
		"sass:[email protected]",
		"[email protected]",
		"[email protected]",
		"[email protected]",
		"[email protected]",
		"[email protected]",
		"[email protected]",
		"[email protected]",
		"[email protected]",
		"dist:[email protected]",
	})

	deploy := c.GetDefault("deploy.mode", "")
	if len(deploy) > 0 {
		q.AddTask(fmt.Sprintf("deploy:%s", deploy))
	}
	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:24,代码来源:build.go

示例11: htmlmin

func htmlmin(c *config.Config, q *registry.Queue) error {
	size := c.CountDefault("htmlmin")
	for i := 0; i < size; i++ {
		source := c.GetRequired("htmlmin[%d].source", i)
		dest := c.GetRequired("htmlmin[%d].dest", i)
		if err := htmlcompressor(source, dest); err != nil {
			return fmt.Errorf("html compress failed: %s", err)
		}
	}

	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:12,代码来源:htmlmin.go

示例12: sassFromConfig

func sassFromConfig(c *config.Config, mode string) ([]*sassFile, error) {
	var from string
	if len(c.GetDefault("closure.library", "")) == 0 {
		if mode == "dev" {
			from = filepath.Join("app")
		} else if mode == "prod" {
			from = filepath.Join("temp")
		}
	}

	files := []*sassFile{}
	size := c.CountRequired("sass")
	for i := 0; i < size; i++ {
		src := filepath.Join(from, "styles", c.GetRequired("sass[%d].source", i))
		dest := filepath.Join("temp", "styles", c.GetRequired("sass[%d].dest", i))
		files = append(files, &sassFile{src, dest})
	}
	return files, nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:19,代码来源:sass.go

示例13: parseAttrs

func parseAttrs(data *config.Config, object string, idx int) map[string]string {
	m := map[string]string{}

	size := data.CountDefault("fields[%d].%s", idx, object)
	for i := 0; i < size; i++ {
		name := data.GetRequired("fields[%d].%s[%d].name", idx, object, i)
		value := data.GetDefault("fields[%d].%s[%d].value", "", idx, object, i)
		m[name] = value
	}

	return m
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:12,代码来源:parse.go

示例14: watch

func watch(c *config.Config, q *registry.Queue) error {
	size := c.CountRequired("watch")
	for i := 0; i < size; i++ {
		// Extract the task name
		task := c.GetRequired("watch[%d].task", i)

		// Extract the paths
		paths := []string{}
		pathsSize := c.CountDefault("watch[%d].paths", i)
		for j := 0; j < pathsSize; j++ {
			paths = append(paths, c.GetRequired("watch[%d].paths[%d]", i, j))
		}

		// Init the watcher
		if err := watcher.Dirs(paths, task); err != nil {
			return fmt.Errorf("watch dirs failed: %s", err)
		}

	}
	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:21,代码来源:watch.go

示例15: lessFromConfig

func lessFromConfig(c *config.Config, mode string) ([]*lessFile, error) {
	var from string
	if mode == "dev" {
		from = "app"
	} else if mode == "prod" {
		from = "temp"
	}

	files := []*lessFile{}
	size := c.CountRequired("recess")
	for i := 0; i < size; i++ {
		src := filepath.Join(from, "styles", c.GetRequired("recess[%d].source", i))
		dest := filepath.Join("temp", "styles", c.GetRequired("recess[%d].dest", i))
		files = append(files, &lessFile{src, dest})
	}
	return files, nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:17,代码来源:recess.go


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