本文整理汇总了Golang中github.com/kylelemons/go-gypsy/yaml.File类的典型用法代码示例。如果您正苦于以下问题:Golang File类的具体用法?Golang File怎么用?Golang File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getItems
func getItems(config yaml.File, key string) ([]*AvailableBlock, error) {
lst, err := validateItems(config, key)
if err != nil {
return nil, errors.New("Invalid items")
}
items := make([]*AvailableBlock, lst.Len())
for i, e := range lst {
itemKey := key + "[" + strconv.Itoa(i) + "]"
title, err := config.Get(itemKey + ".title")
if err != nil {
return nil, errors.New("Missing title")
}
series, err := config.Get(itemKey + ".series")
if err != nil {
series = ""
}
filepathsNode, err := yaml.Child(e, "filepaths")
if err != nil {
return nil, errors.New("Missing filepaths for " + title)
}
publish := true
if key == "extras" {
publish = false
}
items[i] = new(AvailableBlock).Init(title, series, filepathsNode.(yaml.List), publish)
}
return items, nil
}
开发者ID:blizzard-op,项目名称:ipl-playlist,代码行数:28,代码来源:config.go
示例2: YamlList2Slice
func YamlList2Slice(config *yaml.File, text string) []string {
count, err := config.Count(text)
if err != nil {
loge.Error(err)
return nil
}
var result []string
for i := 0; i < count; i++ {
v, err := config.Get(text + "[" + strconv.Itoa(i) + "]")
if err != nil {
loge.Error(err)
return nil
}
result = append(result, v)
}
return result
}
开发者ID:ghw,项目名称:telegram-chinese-groups,代码行数:18,代码来源:helper.go
示例3: YamlList2String
func YamlList2String(config *yaml.File, text string) string {
count, err := config.Count(text)
if err != nil {
log.Println(err)
return ""
}
var resultGroup []string
for i := 0; i < count; i++ {
v, err := config.Get(text + "[" + strconv.Itoa(i) + "]")
if err != nil {
log.Println(err)
return ""
}
resultGroup = append(resultGroup, v)
}
result := strings.Join(resultGroup, "\n")
result = strings.Replace(result, "\\n", "", -1)
return result
}
开发者ID:huoshi5151,项目名称:telegram-chinese-groups,代码行数:22,代码来源:main.go
示例4: confFromYamlFile
// Creates a new SQLConf and returns a pointer to it.
// If it encounters an error during parsing the file,
// it will return an error instead.
func confFromYamlFile(config *yaml.File, goEnv string) (*SQLConf, error) {
// TODO Refactor this into a more generic method of retrieving info
// Get driver
driver, driveError := config.Get(fmt.Sprintf("%s.driver", goEnv))
if driveError != nil {
return nil, driveError
}
// Get openStr
openStr, openStrError := config.Get(fmt.Sprintf("%s.openStr", goEnv))
if openStrError != nil {
return nil, openStrError
}
// Get table
table, tableError := config.Get(fmt.Sprintf("%s.table", goEnv))
if tableError != nil {
return nil, tableError
}
// Get latCol
latCol, latColError := config.Get(fmt.Sprintf("%s.latCol", goEnv))
if latColError != nil {
return nil, latColError
}
// Get lngCol
lngCol, lngColError := config.Get(fmt.Sprintf("%s.lngCol", goEnv))
if lngColError != nil {
return nil, lngColError
}
sqlConf := &SQLConf{driver: driver, openStr: openStr, table: table, latCol: latCol, lngCol: lngCol}
return sqlConf, nil
}
开发者ID:skariuki,项目名称:state-server,代码行数:41,代码来源:sql_conf.go
示例5: ParseConfig
func ParseConfig(config *yaml.File) (*Config, error) {
base, err := config.Get("base")
if err != nil {
return nil, err
}
var rpm *RpmPackage = nil
rpmBaseNode, err := yaml.Child(config.Root, "rpm-base")
if err != nil {
return nil, err
}
if rpmBaseNode != nil {
rpmBaseMap := rpmBaseNode.(yaml.Map)
scalar := rpmBaseMap["name"].(yaml.Scalar)
name := strings.TrimSpace(scalar.String())
scalar = rpmBaseMap["version"].(yaml.Scalar)
version := strings.TrimSpace(scalar.String())
scalar = rpmBaseMap["release"].(yaml.Scalar)
release := strings.TrimSpace(scalar.String())
scalar = rpmBaseMap["arch"].(yaml.Scalar)
arch := strings.TrimSpace(scalar.String())
rpm = &RpmPackage{
Name: name,
Version: version,
Release: release,
Arch: arch,
}
}
cmdline, err := config.Get("cmdline")
if err != nil {
return nil, err
}
build, _ := config.Get("build")
filesNode, err := yaml.Child(config.Root, "files")
if err != nil {
return nil, err
}
files := make(map[string]string)
if filesNode != nil {
filesMap := filesNode.(yaml.Map)
for key, value := range filesMap {
scalar := value.(yaml.Scalar)
files[key] = strings.TrimSpace(scalar.String())
}
}
result := &Config{
Base: base,
RpmBase: rpm,
Cmdline: cmdline,
Build: build,
Files: files,
}
return result, nil
}
开发者ID:posix4e,项目名称:capstan,代码行数:53,代码来源:config.go
示例6: extractConnectionOptions
func extractConnectionOptions(config *yaml.File) (connectionOptions pgx.ConnectionParameters, err error) {
connectionOptions.Host, _ = config.Get("database.host")
connectionOptions.Socket, _ = config.Get("database.socket")
if connectionOptions.Host == "" && connectionOptions.Socket == "" {
err = errors.New("Config must contain database.host or database.socket but it does not")
return
}
port, _ := config.GetInt("database.port")
connectionOptions.Port = uint16(port)
if connectionOptions.Database, err = config.Get("database.database"); err != nil {
err = errors.New("Config must contain database.database but it does not")
return
}
if connectionOptions.User, err = config.Get("database.user"); err != nil {
err = errors.New("Config must contain database.user but it does not")
return
}
connectionOptions.Password, _ = config.Get("database.password")
return
}
开发者ID:jackc,项目名称:lunchkin-db,代码行数:20,代码来源:main.go
示例7: init
func init() {
var err error
var yf *yaml.File
flag.StringVar(&config.listenAddress, "address", "127.0.0.1", "address to listen on")
flag.StringVar(&config.listenPort, "port", "8080", "port to listen on")
flag.StringVar(&config.assetPath, "assetpath", "assets", "path to assets")
flag.StringVar(&config.configPath, "config", "config.yml", "path to config file")
flag.Parse()
givenCliArgs := make(map[string]bool)
flag.Visit(func(f *flag.Flag) {
givenCliArgs[f.Name] = true
})
if config.configPath, err = filepath.Abs(config.configPath); err != nil {
fmt.Fprintf(os.Stderr, "Invalid config path: %v\n", err)
os.Exit(1)
}
if config.assetPath, err = filepath.Abs(config.assetPath); err != nil {
fmt.Fprintf(os.Stderr, "Invalid asset path: %v\n", err)
os.Exit(1)
}
if yf, err = yaml.ReadFile(config.configPath); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
if !givenCliArgs["address"] {
if address, err := yf.Get("address"); err == nil {
config.listenAddress = address
}
}
if !givenCliArgs["assetpath"] {
if assetpath, err := yf.Get("assetpath"); err == nil {
config.assetPath = assetpath
}
}
if !givenCliArgs["port"] {
if port, err := yf.Get("port"); err == nil {
config.listenPort = port
}
}
var connectionParameters pgx.ConnectionParameters
if connectionParameters, err = extractConnectionOptions(yf); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
if err = migrate(connectionParameters); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
poolOptions := pgx.ConnectionPoolOptions{MaxConnections: 5, AfterConnect: afterConnect}
pool, err = pgx.NewConnectionPool(connectionParameters, poolOptions)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create database connection pool: %v\n", err)
os.Exit(1)
}
}
开发者ID:jackc,项目名称:lunchkin-db,代码行数:66,代码来源:main.go
注:本文中的github.com/kylelemons/go-gypsy/yaml.File类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论