本文整理汇总了Golang中github.com/spf13/viper.GetBool函数的典型用法代码示例。如果您正苦于以下问题:Golang GetBool函数的具体用法?Golang GetBool怎么用?Golang GetBool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetBool函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestLoadDefaults
func (s *ConfigTestSuite) TestLoadDefaults(c *C) {
LoadSettingsFromFile()
c.Assert(viper.GetInt("Port"), Equals, Port)
c.Assert(viper.GetBool("EnableAutomerge"), Equals, EnableAutomerge)
c.Assert(viper.GetBool("Debug"), Equals, Debug)
}
开发者ID:slok,项目名称:daton,代码行数:7,代码来源:load_test.go
示例2: RenderSectionLists
// Render a page for each section
func (s *Site) RenderSectionLists() error {
for section, data := range s.Sections {
n := s.NewNode()
if viper.GetBool("PluralizeListTitles") {
n.Title = strings.Title(inflect.Pluralize(section))
} else {
n.Title = strings.Title(section)
}
s.setUrls(n, section)
n.Date = data[0].Page.Date
n.Data["Pages"] = data.Pages()
layouts := []string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"}
err := s.render(n, section, s.appendThemeTemplates(layouts)...)
if err != nil {
return err
}
if !viper.GetBool("DisableRSS") {
// XML Feed
rssLayouts := []string{"section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
s.setUrls(n, section+".xml")
err = s.render(n, section+".xml", s.appendThemeTemplates(rssLayouts)...)
if err != nil {
return err
}
}
}
return nil
}
开发者ID:johnsto,项目名称:hugo,代码行数:31,代码来源:site.go
示例3: copyStatic
func copyStatic() error {
publishDir := helpers.AbsPathify(viper.GetString("publishDir")) + helpers.FilePathSeparator
// If root, remove the second '/'
if publishDir == "//" {
publishDir = helpers.FilePathSeparator
}
// Includes both theme/static & /static
staticSourceFs := getStaticSourceFs()
if staticSourceFs == nil {
jww.WARN.Println("No static directories found to sync")
return nil
}
syncer := fsync.NewSyncer()
syncer.NoTimes = viper.GetBool("notimes")
syncer.SrcFs = staticSourceFs
syncer.DestFs = hugofs.Destination()
// Now that we are using a unionFs for the static directories
// We can effectively clean the publishDir on initial sync
syncer.Delete = viper.GetBool("cleanDestinationDir")
if syncer.Delete {
jww.INFO.Println("removing all files from destination that don't exist in static dirs")
}
jww.INFO.Println("syncing static files to", publishDir)
// because we are using a baseFs (to get the union right).
// set sync src to root
return syncer.Sync(publishDir, helpers.FilePathSeparator)
}
开发者ID:tubo028,项目名称:hugo,代码行数:32,代码来源:hugo.go
示例4: initializeSiteInfo
func (s *Site) initializeSiteInfo() {
params := viper.GetStringMap("Params")
permalinks := make(PermalinkOverrides)
for k, v := range viper.GetStringMapString("Permalinks") {
permalinks[k] = PathPattern(v)
}
s.Info = SiteInfo{
BaseUrl: template.URL(helpers.SanitizeUrlKeepTrailingSlash(viper.GetString("BaseUrl"))),
Title: viper.GetString("Title"),
Author: viper.GetStringMap("author"),
LanguageCode: viper.GetString("languagecode"),
Copyright: viper.GetString("copyright"),
DisqusShortname: viper.GetString("DisqusShortname"),
BuildDrafts: viper.GetBool("BuildDrafts"),
canonifyUrls: viper.GetBool("CanonifyUrls"),
Pages: &s.Pages,
Recent: &s.Pages,
Menus: &s.Menus,
Params: params,
Permalinks: permalinks,
Data: &s.Data,
}
}
开发者ID:dunn,项目名称:hugo,代码行数:25,代码来源:site.go
示例5: createEventHubServer
func createEventHubServer() (net.Listener, *grpc.Server, error) {
var lis net.Listener
var grpcServer *grpc.Server
var err error
if viper.GetBool("peer.validator.enabled") {
lis, err = net.Listen("tcp", viper.GetString("peer.validator.events.address"))
if err != nil {
return nil, nil, fmt.Errorf("failed to listen: %v", err)
}
//TODO - do we need different SSL material for events ?
var opts []grpc.ServerOption
if viper.GetBool("peer.tls.enabled") {
creds, err := credentials.NewServerTLSFromFile(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file"))
if err != nil {
return nil, nil, fmt.Errorf("Failed to generate credentials %v", err)
}
opts = []grpc.ServerOption{grpc.Creds(creds)}
}
grpcServer = grpc.NewServer(opts...)
ehServer := producer.NewOpenchainEventsServer(uint(viper.GetInt("peer.validator.events.buffersize")), viper.GetInt("peer.validator.events.timeout"))
pb.RegisterOpenchainEventsServer(grpcServer, ehServer)
}
return lis, grpcServer, err
}
开发者ID:tenc,项目名称:obc-peer-pre-public,代码行数:26,代码来源:main.go
示例6: getConfig
//getConfig reads config and returns struct
func getConfig() (c Config) {
c.SnippetDir = expandPath(viper.GetString("snippet_dir"))
c.Shell = viper.GetString("shell")
c.AppendHistory = viper.GetBool("append_history")
c.ExecConfirm = viper.GetBool("exec_confirm")
return c
}
开发者ID:livitski,项目名称:sman,代码行数:8,代码来源:config.go
示例7: permalink
func (p *Page) permalink() (*url.URL, error) {
baseUrl := string(p.Site.BaseUrl)
dir := strings.TrimSpace(p.Dir)
pSlug := strings.TrimSpace(p.Slug)
pUrl := strings.TrimSpace(p.Url)
var permalink string
var err error
if len(pUrl) > 0 {
return helpers.MakePermalink(baseUrl, pUrl), nil
}
if override, ok := p.Site.Permalinks[p.Section]; ok {
permalink, err = override.Expand(p)
if err != nil {
return nil, err
}
// fmt.Printf("have a section override for %q in section %s → %s\n", p.Title, p.Section, permalink)
} else {
if len(pSlug) > 0 {
permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, p.Slug+"."+p.Extension))
} else {
_, t := path.Split(p.FileName)
permalink = helpers.UrlPrep(viper.GetBool("UglyUrls"), path.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension)))
}
}
return helpers.MakePermalink(baseUrl, permalink), nil
}
开发者ID:vinchu,项目名称:hugo,代码行数:30,代码来源:page.go
示例8: getAndValidateConfig
func (a *appConfig) getAndValidateConfig(cmd *cobra.Command) error {
var err error
a.port = viper.GetString("port")
a.debug = viper.GetBool("debug")
a.cpu = viper.GetInt("cpu")
a.allowDegradedMode = viper.GetBool("allow-degraded-mode")
// check logLevel values and set initLogLevel
a.logLevel = viper.GetString("log-level")
a.initLogLevel, err = log.ParseLevel(a.logLevel)
if err != nil {
err = fmt.Errorf("Invalid log level: \"%s\"\n%s", a.logLevel, cmd.Flags().Lookup("log-level").Usage)
return err
}
// check db name
a.db = viper.GetString("db")
if a.db == "" {
err = fmt.Errorf("Db name can't be empty\n%s", cmd.Flags().Lookup("db").Usage)
return err
}
// Kafka brokers
a.kafkaBrokerList = strings.Split(viper.GetString("kafka-brokers"), ",")
if len(a.kafkaBrokerList) == 0 {
err = fmt.Errorf("Broker list is empty or invalid format (%s)\n%s", a.kafkaBrokers, cmd.Flags().Lookup("kafka-brokers").Usage)
return err
}
return nil
}
开发者ID:wojtekzw,项目名称:event-shuttle,代码行数:32,代码来源:event-shuttle.go
示例9: getSecHelper
func getSecHelper() (crypto.Peer, error) {
var secHelper crypto.Peer
var err error
if viper.GetBool("security.enabled") {
enrollID := viper.GetString("security.enrollID")
enrollSecret := viper.GetString("security.enrollSecret")
if viper.GetBool("peer.validator.enabled") {
if err = crypto.RegisterValidator(enrollID, nil, enrollID, enrollSecret); nil != err {
return nil, err
}
secHelper, err = crypto.InitValidator(enrollID, nil)
if nil != err {
return nil, err
}
} else {
if err = crypto.RegisterPeer(enrollID, nil, enrollID, enrollSecret); nil != err {
return nil, err
}
secHelper, err = crypto.InitPeer(enrollID, nil)
if nil != err {
return nil, err
}
}
}
return secHelper, err
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:26,代码来源:validity_period_test.go
示例10: permalink
func (p *Page) permalink() (*url.URL, error) {
baseURL := string(p.Site.BaseURL)
dir := strings.TrimSpace(helpers.MakePath(filepath.ToSlash(strings.ToLower(p.Source.Dir()))))
pSlug := strings.TrimSpace(helpers.URLize(p.Slug))
pURL := strings.TrimSpace(helpers.URLize(p.URL))
var permalink string
var err error
if len(pURL) > 0 {
return helpers.MakePermalink(baseURL, pURL), nil
}
if override, ok := p.Site.Permalinks[p.Section()]; ok {
permalink, err = override.Expand(p)
if err != nil {
return nil, err
}
// fmt.Printf("have a section override for %q in section %s → %s\n", p.Title, p.Section, permalink)
} else {
if len(pSlug) > 0 {
permalink = helpers.URLPrep(viper.GetBool("UglyURLs"), path.Join(dir, p.Slug+"."+p.Extension()))
} else {
_, t := filepath.Split(p.Source.LogicalName())
permalink = helpers.URLPrep(viper.GetBool("UglyURLs"), path.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension())))
}
}
return helpers.MakePermalink(baseURL, permalink), nil
}
开发者ID:JTrembl1,项目名称:hugo,代码行数:30,代码来源:page.go
示例11: initializeSiteInfo
func (s *Site) initializeSiteInfo() {
params := viper.GetStringMap("Params")
permalinks := make(PermalinkOverrides)
for k, v := range viper.GetStringMapString("Permalinks") {
permalinks[k] = PathPattern(v)
}
s.Info = SiteInfo{
BaseURL: template.URL(helpers.SanitizeURLKeepTrailingSlash(viper.GetString("BaseURL"))),
Title: viper.GetString("Title"),
Author: viper.GetStringMap("author"),
Social: viper.GetStringMapString("social"),
LanguageCode: viper.GetString("languagecode"),
Copyright: viper.GetString("copyright"),
DisqusShortname: viper.GetString("DisqusShortname"),
GoogleAnalytics: viper.GetString("GoogleAnalytics"),
RSSLink: s.permalinkStr(viper.GetString("RSSUri")),
BuildDrafts: viper.GetBool("BuildDrafts"),
canonifyURLs: viper.GetBool("CanonifyURLs"),
preserveTaxonomyNames: viper.GetBool("PreserveTaxonomyNames"),
Pages: &s.Pages,
Menus: &s.Menus,
Params: params,
Permalinks: permalinks,
Data: &s.Data,
}
}
开发者ID:maruel,项目名称:hugo,代码行数:28,代码来源:site.go
示例12: renderAndWritePage
func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
renderBuffer := bp.GetBuffer()
defer bp.PutBuffer(renderBuffer)
err := s.render(name, d, renderBuffer, layouts...)
outBuffer := bp.GetBuffer()
defer bp.PutBuffer(outBuffer)
transformLinks := transform.NewEmptyTransforms()
if viper.GetBool("CanonifyUrls") {
absURL, err := transform.AbsURL(viper.GetString("BaseUrl"))
if err != nil {
return err
}
transformLinks = append(transformLinks, absURL...)
}
if viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
transformLinks = append(transformLinks, transform.LiveReloadInject)
}
transformer := transform.NewChain(transformLinks...)
transformer.Apply(outBuffer, renderBuffer)
if err == nil {
if err = s.WriteDestPage(dest, outBuffer); err != nil {
return err
}
}
return err
}
开发者ID:dunn,项目名称:hugo,代码行数:33,代码来源:site.go
示例13: getDockerHostConfig
func getDockerHostConfig() *docker.HostConfig {
if hostConfig != nil {
return hostConfig
}
dockerKey := func(key string) string {
return "vm.docker.hostConfig." + key
}
getInt64 := func(key string) int64 {
defer func() {
if err := recover(); err != nil {
dockerLogger.Warningf("load vm.docker.hostConfig.%s failed, error: %v", key, err)
}
}()
n := viper.GetInt(dockerKey(key))
return int64(n)
}
var logConfig docker.LogConfig
err := viper.UnmarshalKey(dockerKey("LogConfig"), &logConfig)
if err != nil {
dockerLogger.Warningf("load docker HostConfig.LogConfig failed, error: %s", err.Error())
}
networkMode := viper.GetString(dockerKey("NetworkMode"))
if networkMode == "" {
networkMode = "host"
}
dockerLogger.Debugf("docker container hostconfig NetworkMode: %s", networkMode)
hostConfig = &docker.HostConfig{
CapAdd: viper.GetStringSlice(dockerKey("CapAdd")),
CapDrop: viper.GetStringSlice(dockerKey("CapDrop")),
DNS: viper.GetStringSlice(dockerKey("Dns")),
DNSSearch: viper.GetStringSlice(dockerKey("DnsSearch")),
ExtraHosts: viper.GetStringSlice(dockerKey("ExtraHosts")),
NetworkMode: networkMode,
IpcMode: viper.GetString(dockerKey("IpcMode")),
PidMode: viper.GetString(dockerKey("PidMode")),
UTSMode: viper.GetString(dockerKey("UTSMode")),
LogConfig: logConfig,
ReadonlyRootfs: viper.GetBool(dockerKey("ReadonlyRootfs")),
SecurityOpt: viper.GetStringSlice(dockerKey("SecurityOpt")),
CgroupParent: viper.GetString(dockerKey("CgroupParent")),
Memory: getInt64("Memory"),
MemorySwap: getInt64("MemorySwap"),
MemorySwappiness: getInt64("MemorySwappiness"),
OOMKillDisable: viper.GetBool(dockerKey("OomKillDisable")),
CPUShares: getInt64("CpuShares"),
CPUSet: viper.GetString(dockerKey("Cpuset")),
CPUSetCPUs: viper.GetString(dockerKey("CpusetCPUs")),
CPUSetMEMs: viper.GetString(dockerKey("CpusetMEMs")),
CPUQuota: getInt64("CpuQuota"),
CPUPeriod: getInt64("CpuPeriod"),
BlkioWeight: getInt64("BlkioWeight"),
}
return hostConfig
}
开发者ID:srderson,项目名称:fabric,代码行数:59,代码来源:dockercontroller.go
示例14: initPeer
//initialize peer and start up. If security==enabled, login as vp
func initPeer(chainID string) (net.Listener, error) {
//start clean
finitPeer(nil)
var opts []grpc.ServerOption
if viper.GetBool("peer.tls.enabled") {
creds, err := credentials.NewServerTLSFromFile(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file"))
if err != nil {
return nil, fmt.Errorf("Failed to generate credentials %v", err)
}
opts = []grpc.ServerOption{grpc.Creds(creds)}
}
grpcServer := grpc.NewServer(opts...)
viper.Set("peer.fileSystemPath", filepath.Join(os.TempDir(), "hyperledger", "production"))
peerAddress, err := peer.GetLocalAddress()
if err != nil {
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
}
lis, err := net.Listen("tcp", peerAddress)
if err != nil {
return nil, fmt.Errorf("Error starting peer listener %s", err)
}
//initialize ledger
peer.MockInitialize()
getPeerEndpoint := func() (*pb.PeerEndpoint, error) {
return &pb.PeerEndpoint{ID: &pb.PeerID{Name: "testpeer"}, Address: peerAddress}, nil
}
// Install security object for peer
if viper.GetBool("security.enabled") {
//TODO: integrate new crypto / idp
securityLevel := viper.GetInt("security.level")
hashAlgorithm := viper.GetString("security.hashAlgorithm")
primitives.SetSecurityLevel(hashAlgorithm, securityLevel)
} else {
// the primitives need to be instantiated no matter what. Otherwise
// the escc code won't have a hash algorithm available to hash the proposal
primitives.SetSecurityLevel("SHA2", 256)
}
ccStartupTimeout := time.Duration(30000) * time.Millisecond
pb.RegisterChaincodeSupportServer(grpcServer, chaincode.NewChaincodeSupport(getPeerEndpoint, false, ccStartupTimeout))
chaincode.RegisterSysCCs()
if err = peer.MockCreateChain(chainID); err != nil {
closeListenerAndSleep(lis)
return nil, err
}
chaincode.DeploySysCCs(chainID)
go grpcServer.Serve(lis)
return lis, nil
}
开发者ID:hyperledger,项目名称:fabric,代码行数:60,代码来源:endorser_test.go
示例15: ShouldBuild
func (p *Page) ShouldBuild() bool {
if viper.GetBool("BuildFuture") || p.PublishDate.IsZero() || p.PublishDate.Before(time.Now()) {
if viper.GetBool("BuildDrafts") || !p.Draft {
return true
}
}
return false
}
开发者ID:JTrembl1,项目名称:hugo,代码行数:8,代码来源:page.go
示例16: GetBool
// GetBool returns a config value as a bool.
func (c *LiveConfig) GetBool(ns, key string) bool {
if ns == NSRoot {
return viper.GetBool(key)
}
nskey := fmt.Sprintf("%s-%s", ns, key)
return viper.GetBool(nskey)
}
开发者ID:neurodrone,项目名称:doit,代码行数:9,代码来源:doit.go
示例17: BlockCode
func (renderer *HugoMmarkHTMLRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string, caption []byte, subfigure bool, callouts bool) {
if viper.GetBool("PygmentsCodeFences") && (lang != "" || viper.GetBool("PygmentsCodeFencesGuessSyntax")) {
str := html.UnescapeString(string(text))
out.WriteString(Highlight(str, lang, ""))
} else {
renderer.Renderer.BlockCode(out, text, lang, caption, subfigure, callouts)
}
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:8,代码来源:content_renderer.go
示例18: loadOAuth2Config
func loadOAuth2Config() {
Config.OAuth2Enabled = viper.GetBool("stormpath.web.oauth2.enabled")
Config.OAuth2URI = viper.GetString("stormpath.web.oauth2.uri")
Config.OAuth2ClientCredentialsGrantTypeEnabled = viper.GetBool("stormpath.web.oauth2.client_credentials.enabled")
Config.OAuth2ClientCredentialsGrantTypeAccessTokenTTL = time.Duration(viper.GetInt("stormpath.web.oauth2.client_credentials.accessToken.ttl")) * time.Second
Config.OAuth2PasswordGrantTypeEnabled = viper.GetBool("stormpath.web.oauth2.password.enabled")
Config.OAuth2PasswordGrantTypeValidationStrategy = viper.GetString("stormpath.web.oauth2.password.validationStrategy")
}
开发者ID:jxstanford,项目名称:stormpath-sdk-go,代码行数:8,代码来源:config.go
示例19: setupAPI
func setupAPI() *msgraph.GraphAPI {
api := msgraph.New(viper.GetString("tenantDomain"))
api.SetDebug(viper.GetBool("debug"))
api.SetHTTPDebug(viper.GetBool("httpdebug"))
api.SetClientID(viper.GetString("clientID"))
api.SetClientSecret(viper.GetString("clientSecret"))
return api
}
开发者ID:Crosse,项目名称:msgraph,代码行数:9,代码来源:userGet.go
示例20: LoadConfigFile
func LoadConfigFile() error {
if ConfigFile == "" {
return nil
}
// Set defaults to whatever might be there already
viper.SetDefault("api-token", ApiToken)
viper.SetDefault("api-host", ApiHost)
viper.SetDefault("api-port", ApiPort)
viper.SetDefault("api-key", ApiKey)
viper.SetDefault("api-cert", ApiCert)
viper.SetDefault("api-key-password", ApiKeyPassword)
viper.SetDefault("db-connection", DatabaseConnection)
viper.SetDefault("cluster-connection", ClusterConnection)
viper.SetDefault("cluster-token", ClusterToken)
viper.SetDefault("insecure", Insecure)
viper.SetDefault("just-proxy", JustProxy)
viper.SetDefault("log-level", LogLevel)
viper.SetDefault("log-file", LogFile)
viper.SetDefault("server", Server)
viper.SetDefault("proxy-http", RouteHttp)
viper.SetDefault("proxy-tls", RouteTls)
viper.SetDefault("proxy-ignore-upstream", ProxyIgnore)
viper.SetDefault("balancer", Balancer)
viper.SetDefault("work-dir", WorkDir)
filename := filepath.Base(ConfigFile)
viper.SetConfigName(filename[:len(filename)-len(filepath.Ext(filename))])
viper.AddConfigPath(filepath.Dir(ConfigFile))
err := viper.ReadInConfig()
if err != nil {
return fmt.Errorf("Fatal error config file: %s \n", err)
}
// Set values. Config file will override commandline
ApiToken = viper.GetString("api-token")
ApiHost = viper.GetString("api-host")
ApiPort = viper.GetString("api-port")
ApiKey = viper.GetString("api-key")
ApiCert = viper.GetString("api-cert")
ApiKeyPassword = viper.GetString("api-key-password")
DatabaseConnection = viper.GetString("db-connection")
ClusterConnection = viper.GetString("cluster-connection")
ClusterToken = viper.GetString("cluster-token")
Insecure = viper.GetBool("insecure")
JustProxy = viper.GetBool("just-proxy")
LogLevel = viper.GetString("log-level")
LogFile = viper.GetString("log-file")
Server = viper.GetBool("server")
RouteHttp = viper.GetString("proxy-http")
RouteTls = viper.GetString("proxy-tls")
ProxyIgnore = viper.GetBool("proxy-ignore-upstream")
Balancer = viper.GetString("balancer")
WorkDir = viper.GetString("work-dir")
return nil
}
开发者ID:nanopack,项目名称:portal,代码行数:57,代码来源:config.go
注:本文中的github.com/spf13/viper.GetBool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论