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


Golang cast.ToString函数代码示例

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


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

示例1: getParam

func (p *Page) getParam(key string, stringToLower bool) interface{} {
	v := p.Params[strings.ToLower(key)]

	if v == nil {
		return nil
	}

	switch v.(type) {
	case bool:
		return cast.ToBool(v)
	case string:
		if stringToLower {
			return strings.ToLower(cast.ToString(v))
		}
		return cast.ToString(v)
	case int64, int32, int16, int8, int:
		return cast.ToInt(v)
	case float64, float32:
		return cast.ToFloat64(v)
	case time.Time:
		return cast.ToTime(v)
	case []string:
		if stringToLower {
			return helpers.SliceToLower(v.([]string))
		}
		return v.([]string)
	case map[string]interface{}: // JSON and TOML
		return v
	case map[interface{}]interface{}: // YAML
		return v
	}

	jww.ERROR.Printf("GetParam(\"%s\"): Unknown type %s\n", key, reflect.TypeOf(v))
	return nil
}
开发者ID:JTrembl1,项目名称:hugo,代码行数:35,代码来源:page.go

示例2: toSortedLanguages

func toSortedLanguages(l map[string]interface{}) (helpers.Languages, error) {
	langs := make(helpers.Languages, len(l))
	i := 0

	for lang, langConf := range l {
		langsMap, err := cast.ToStringMapE(langConf)

		if err != nil {
			return nil, fmt.Errorf("Language config is not a map: %T", langConf)
		}

		language := helpers.NewLanguage(lang)

		for loki, v := range langsMap {
			switch loki {
			case "title":
				language.Title = cast.ToString(v)
			case "languagename":
				language.LanguageName = cast.ToString(v)
			case "weight":
				language.Weight = cast.ToInt(v)
			}

			// Put all into the Params map
			language.SetParam(loki, v)
		}

		langs[i] = language
		i++
	}

	sort.Sort(langs)

	return langs, nil
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:35,代码来源:multilingual.go

示例3: GetConfig

// GetConfig return configuration instance
func GetConfig() Config {
	config := Config{
		LinguaLeo: linguaLeo{
			Email:    cast.ToString(viper.Get("lingualeo.email")),
			Password: cast.ToString(viper.Get("lingualeo.password")),
		},
	}
	return config
}
开发者ID:igrybkov,项目名称:leosync,代码行数:10,代码来源:config.go

示例4: IsLess

func (rs *SortableRowSet) IsLess(origin *TableRow, than *TableRow) bool {
	for _, val := range rs.cols {
		if val.Orderable && val.Order != ORDER_UNDEFINED {
			if res := strings.Compare(cast.ToString(origin.Data[val.Name]), cast.ToString(than.Data[val.Name])); res != 0 {
				if val.Order == ORDER_DESC {
					return res == -1
				} else {
					return res == 1
				}
			}
		}
	}
	//no ordering provided, base on string pointers
	return strings.Compare(fmt.Sprintf("%p", origin.Data), fmt.Sprintf("%p", than.Data)) == -1
}
开发者ID:RobinUS2,项目名称:indispenso,代码行数:15,代码来源:sortable_rowset.go

示例5: parseOrdering

func parseOrdering(formValues map[string]interface{}) map[string]DataTableOrder {
	ordering := map[string]DataTableOrder{}
	if orders, ok := formValues["order"]; ok {
		for _, val := range orders.(map[string]interface{}) {
			mapValue := val.(map[string]interface{})
			column, columnExists := mapValue["column"]
			dir, dirExists := mapValue["dir"]
			if columnExists && dirExists {
				ordering[cast.ToString(column)] = DataTableOrder(cast.ToString(dir))
			}
		}
	}

	return ordering
}
开发者ID:RobinUS2,项目名称:indispenso,代码行数:15,代码来源:core.go

示例6: MarshallMap

func (me *MenuEntry) MarshallMap(ime map[string]interface{}) {
	for k, v := range ime {
		loki := strings.ToLower(k)
		switch loki {
		case "url":
			me.Url = cast.ToString(v)
		case "weight":
			me.Weight = cast.ToInt(v)
		case "name":
			me.Name = cast.ToString(v)
		case "parent":
			me.Parent = cast.ToString(v)
		}
	}
}
开发者ID:nathanleclaire,项目名称:hugo,代码行数:15,代码来源:menu.go

示例7: Get

// Get returns an interface..
// Must be typecast or used by something that will typecast
func (manager *Config) Get(key string) interface{} {
	jww.TRACE.Println("Looking for", key)

	v := manager.Find(key)

	if v == nil {
		return nil
	}

	jww.TRACE.Println("Found value", v)
	switch v.(type) {
	case bool:
		return cast.ToBool(v)
	case string:
		return cast.ToString(v)
	case int64, int32, int16, int8, int:
		return cast.ToInt(v)
	case float64, float32:
		return cast.ToFloat64(v)
	case time.Time:
		return cast.ToTime(v)
	case []string:
		return v
	}
	return v
}
开发者ID:MightyE,项目名称:confer,代码行数:28,代码来源:confer.go

示例8: Get

func (v *Viper) Get(key string) interface{} {
	key = strings.ToLower(key)
	val := v.find(key)

	if val == nil {
		return nil
	}

	switch val.(type) {
	case bool:
		return cast.ToBool(val)
	case string:
		return cast.ToString(val)
	case int64, int32, int16, int8, int:
		return cast.ToInt(val)
	case float64, float32:
		return cast.ToFloat64(val)
	case time.Time:
		return cast.ToTime(val)
	case time.Duration:
		return cast.ToDuration(val)
	case []string:
		return val
	}
	return val
}
开发者ID:pandemicsyn,项目名称:stalker,代码行数:26,代码来源:viper.go

示例9: FilterRow

func (ds *DefaultStore) FilterRow(row *TableRow, filter *SearchDefinition, rowSet RowSet) bool {
	if row == nil || len(row.Data) == 0 {
		return false
	}
	foundGlobally := true
	for name, value := range row.Data {
		strValue := cast.ToString(value)

		if filter.IsApplicable() {
			if filter.IsMatch(strValue) {
				return true
			} else {
				foundGlobally = false
			}
		}

		if col := rowSet.ColumnByName(name); col != nil {
			if col.Searchable && col.Search.IsApplicable() {
				if !col.Search.IsMatch(strValue) {
					return false
				}
			}
		}
	}

	return foundGlobally
}
开发者ID:RobinUS2,项目名称:indispenso,代码行数:27,代码来源:default_store.go

示例10: Get

func (v *Viper) Get(key string) interface{} {
	lcaseKey := strings.ToLower(key)
	val := v.find(lcaseKey)
	if val == nil {
		return nil
	}

	valType := val
	if v.typeByDefValue {
		// TODO(bep) this branch isn't covered by a single test.
		path := strings.Split(lcaseKey, v.keyDelim)
		defVal := v.searchMap(v.defaults, path)
		if defVal != nil {
			valType = defVal
		}
	}

	switch valType.(type) {
	case bool:
		return cast.ToBool(val)
	case string:
		return cast.ToString(val)
	case int64, int32, int16, int8, int:
		return cast.ToInt(val)
	case float64, float32:
		return cast.ToFloat64(val)
	case time.Time:
		return cast.ToTime(val)
	case time.Duration:
		return cast.ToDuration(val)
	case []string:
		return cast.ToStringSlice(val)
	}
	return val
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:35,代码来源:viper.go

示例11: markdownify

// markdownify renders a given string from Markdown to HTML.
func markdownify(in interface{}) template.HTML {
	text := cast.ToString(in)
	m := helpers.RenderBytes(&helpers.RenderingContext{Content: []byte(text), PageFmt: "markdown"})
	m = bytes.TrimPrefix(m, markdownTrimPrefix)
	m = bytes.TrimSuffix(m, markdownTrimSuffix)
	return template.HTML(m)
}
开发者ID:camunda-third-party,项目名称:hugo,代码行数:8,代码来源:template_funcs.go

示例12: AutoRepair

func (c *Conf) AutoRepair() {
	fullUriPattern, _ := regexp.Compile("(http[s]{0,1})://([^/:]+):?([0-9]{0,}).*")
	if !fullUriPattern.MatchString(c.EndpointURI) {
		protocol := "https"
		host := getDefaultHostName()
		port := cast.ToString(c.ServerPort)
		hostWithPortPattern, _ := regexp.Compile("([^:/]+):?([0-9]{0,})")
		repaired := false

		if hostWithPortPattern.MatchString(c.EndpointURI) {
			matches := hostWithPortPattern.FindAllStringSubmatch(c.EndpointURI, -1)
			if val := matches[0][1]; val != "" {
				host = val
			}
			if val := matches[0][2]; val != "" {
				port = val
			}
			repaired = true
		}

		if repaired {
			c.EndpointURI = fmt.Sprintf("%s://%s:%s/", protocol, host, port)
			log.Printf("EndpointURI successfully reparied to: %s", c.EndpointURI)
		}
	}
}
开发者ID:RobinUS2,项目名称:indispenso,代码行数:26,代码来源:conf.go

示例13: loadRedirects

func (c *Config) loadRedirects(seq sequence) {
	// if seq.valForKey("redirects") != "" {
	// 	panic("Configuration error: redirects should be a list of paths and destinations")
	// }
	// TODO: assert right content types (not string val, not value sequence)
	c.redirects = make(map[string]string)
	for _, el := range seq.seqForKey("redirects") {
		path := cast.ToString(el.key)
		dest := cast.ToString(el.value)
		if strings.HasPrefix(path, "/") {
			c.redirects[path[1:]] = dest
		} else {
			c.redirects[path] = dest
		}
	}
}
开发者ID:michaeldwan,项目名称:static,代码行数:16,代码来源:config.go

示例14: loadS3Bucket

func (c *Config) loadS3Bucket(seq sequence) {
	val := cast.ToString(seq.valForKey("s3_bucket"))
	if val == "" {
		panic("Configuration error: s3_bucket is missing")
	}
	c.S3Bucket = val
}
开发者ID:michaeldwan,项目名称:static,代码行数:7,代码来源:config.go

示例15: loadS3Region

func (c *Config) loadS3Region(seq sequence) {
	val := cast.ToString(seq.valForKey("s3_region"))
	if val == "" {
		val = s3RegionDefault
	}
	c.S3Region = val
}
开发者ID:michaeldwan,项目名称:static,代码行数:7,代码来源:config.go


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