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


Golang cast.ToStringSliceE函数代码示例

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


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

示例1: StringSlice

func (self *Options) StringSlice(key string) []string {
	value, err := cast.ToStringSliceE(self.Interface(key))
	if err != nil {
		self.log.Printf("%s for key '%s'", err.Error(), key)
	}
	return value
}
开发者ID:thrawn01,项目名称:args,代码行数:7,代码来源:options.go

示例2: Menus

func (p *Page) Menus() PageMenus {
	p.pageMenusInit.Do(func() {
		p.pageMenus = PageMenus{}

		if ms, ok := p.Params["menu"]; ok {
			link, _ := p.RelPermalink()

			me := MenuEntry{Name: p.LinkTitle(), Weight: p.Weight, URL: link}

			// Could be the name of the menu to attach it to
			mname, err := cast.ToStringE(ms)

			if err == nil {
				me.Menu = mname
				p.pageMenus[mname] = &me
				return
			}

			// Could be a slice of strings
			mnames, err := cast.ToStringSliceE(ms)

			if err == nil {
				for _, mname := range mnames {
					me.Menu = mname
					p.pageMenus[mname] = &me
				}
				return
			}

			// Could be a structured menu entry
			menus, err := cast.ToStringMapE(ms)

			if err != nil {
				jww.ERROR.Printf("unable to process menus for %q\n", p.Title)
			}

			for name, menu := range menus {
				menuEntry := MenuEntry{Name: p.LinkTitle(), URL: link, Weight: p.Weight, Menu: name}
				if menu != nil {
					jww.DEBUG.Printf("found menu: %q, in %q\n", name, p.Title)
					ime, err := cast.ToStringMapE(menu)
					if err != nil {
						jww.ERROR.Printf("unable to process menus for %q: %s", p.Title, err)
					}

					menuEntry.marshallMap(ime)
				}
				p.pageMenus[name] = &menuEntry

			}
		}
	})

	return p.pageMenus
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:55,代码来源:page.go

示例3: Menus

func (page *Page) Menus() PageMenus {
	ret := PageMenus{}

	if ms, ok := page.Params["menu"]; ok {
		link, _ := page.Permalink()

		me := MenuEntry{Name: page.LinkTitle(), Weight: page.Weight, Url: link}

		// Could be the name of the menu to attach it to
		mname, err := cast.ToStringE(ms)

		if err == nil {
			me.Menu = mname
			ret[mname] = &me
			return ret
		}

		// Could be an slice of strings
		mnames, err := cast.ToStringSliceE(ms)

		if err == nil {
			for _, mname := range mnames {
				me.Menu = mname
				ret[mname] = &me
				return ret
			}
		}

		// Could be a structured menu entry
		menus, err := cast.ToStringMapE(ms)

		if err != nil {
			jww.ERROR.Printf("unable to process menus for %q\n", page.Title)
		}

		for name, menu := range menus {
			menuEntry := MenuEntry{Name: page.LinkTitle(), Url: link, Weight: page.Weight, Menu: name}
			jww.DEBUG.Printf("found menu: %q, in %q\n", name, page.Title)

			ime, err := cast.ToStringMapE(menu)
			if err != nil {
				jww.ERROR.Printf("unable to process menus for %q\n", page.Title)
			}

			menuEntry.MarshallMap(ime)
			ret[name] = &menuEntry
		}
		return ret
	}

	return nil
}
开发者ID:vinchu,项目名称:hugo,代码行数:52,代码来源:page.go

示例4: TestConvertAllDocs

func TestConvertAllDocs(t *testing.T) {
	err := convertAllDocs()
	assert.Equal(t, nil, err)

	metadata_en, content_en, err := getMetadata("content/doc/commands/hugo_new_en.md")
	assert.Equal(t, nil, err)
	docs_en, err := cast.ToStringSliceE(metadata_en["doc"])
	assert.Equal(t, nil, err)
	assert.Equal(t, "commands_en", docs_en[0])
	assert.NotEqual(t, 0, len(content_en))

	metadata, content, err := getMetadata("content/doc/commands/hugo_new.md")
	assert.Equal(t, nil, err)
	docs, err := cast.ToStringSliceE(metadata["doc"])
	assert.Equal(t, nil, err)
	assert.Equal(t, "commands", docs[0])
	assert.NotEqual(t, 0, len(content))

	// exclude showcase dir
	_, err = os.Stat("/content/doc/showcase/spf13.md")
	assert.True(t, os.IsNotExist(err))
}
开发者ID:coderzh,项目名称:gohugo.org,代码行数:22,代码来源:updatedoc_test.go


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