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

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

示例1: Serve

// Serve starts Goji using reasonable defaults.
func Serve() {
    if !flag.Parsed() {
        flag.Parse()
    }

    log.SetFlags(log.Flags() | log.Lmicroseconds)

    // Install our handler at the root of the standard net/http default mux.
    // This allows packages like expvar to continue working as expected.
    http.Handle("/", DefaultMux)

    listener := bind.Default()
    log.Println("Starting Goji on", listener.Addr())

    graceful.HandleSignals()
    bind.Ready()

    err := graceful.Serve(listener, http.DefaultServeMux)

    if err != nil {
        log.Fatal(err)
    }

    graceful.Wait()
}

开发者ID:brandonparsons,项目名称:simulation.retirementplan.io,代码行数:26,代码来源:goji.go

示例2: Initialize

// Initialize constructs appropriate Credential structure based on
// provided data, which includes, in the following precedence (later
// superseding earlier):
// * In case of username/password auth:
//   1. As keys UsernameKey and PasswordKey in ~/.romana.yaml file
//   2. As environment variables whose names are UsernameKey and PasswordKey values
//   3. As --username and --password command-line flags.
//      If --username flag is specified but --password flag is omitted,
//      the user will be prompted for the password.
// Notes:
// 1. The first two precedence steps (~/.romana.yaml and environment variables)
//    are taken care by the config module (github.com/spf13/viper)
// 2. If flag.Parsed() is false at the time of this call, the command-line values are
//    ignored.
//
func (c *Credential) Initialize() error {
    username := config.GetString(UsernameKey)
    password := config.GetString(PasswordKey)
    if c.assumeFlagParsed || flag.Parsed() {
        if c.userFlag != "" {
            username = c.userFlag
            if c.passFlag == "" {
                // Ask for password
                var err error
                password, err = GetPasswd()
                if err != nil {
                    return err
                }
            } else {
                password = c.passFlag
            }
        }
    }
    if username != "" {
        //
        c.Username = username
        c.Password = password
        c.Type = CredentialUsernamePassword
    } else {
        // For now, credential is None if not specified
        c.Type = CredentialNone
    }
    return nil
}

开发者ID:romana,项目名称:core,代码行数:44,代码来源:auth.go

示例3: loadConfig

func loadConfig() (*Config, error) {

    var configFlag string
    var versionFlag bool

    if !flag.Parsed() {
        flag.StringVar(&configFlag, "config", "",
            "JSON config or file:// path to JSON config file.")
        flag.BoolVar(&versionFlag, "version", false, "Show version identifier and quit.")
        flag.Parse()
    } else {
        // allows for safe configuration reload
        configFlag = flag.Lookup("config").Value.String()
    }
    if versionFlag {
        fmt.Printf("Version: %s\nGitHash: %s\n", Version, GitHash)
        os.Exit(0)
    }
    if configFlag == "" {
        configFlag = os.Getenv("CONTAINERBUDDY")
    }

    config, err := parseConfig(configFlag)
    if err != nil {
        return nil, err
    }
    return initializeConfig(config)
}

开发者ID:zofuthan,项目名称:containerbuddy,代码行数:28,代码来源:config.go

示例4: createNewFiles

// createNewFiles creates all the log files for severity from sev down to infoLog.
// l.mu is held.
func (l *loggingT) createNewFiles() error {
    l.mu.Lock()
    defer l.mu.Unlock()

    if !flag.Parsed() {
        return fmt.Errorf("ERROR: logging before flag.Parse: ")
    } else if l.toStderr {
        return nil
    }

    now := time.Now()
    // Files are created in decreasing severity order, so as soon as we find one
    // has already been created, we can stop.
    for s := fatalLog; s >= infoLog; s-- {
        if l.file[s] == nil {
            continue
        }

        if sb, ok := l.file[s].(*syncBuffer); ok {
            if err := sb.rotateFile(now); err != nil {
                return err
            }
        }
    }

    return nil
}

开发者ID:chinawebeye,项目名称:glog,代码行数:29,代码来源:glog.go

示例5: HandlerFunc

// HandlerFunc returns the http handler func, which renders the
// template with the data.
func (p page) HandlerFunc() http.HandlerFunc {
    fn := func(w http.ResponseWriter, r *http.Request) {
        data, err := p.getTemplateData(w, r)
        if err != nil {
            glog.Errorf("error getting template data: %v\n", err)
            serveISE(w)
            return
        }
        err = p.tmpl.ExecuteTemplate(w, baseTemplate, data)
        if err != nil {
            glog.Errorf("error rendering template: %v\n", err)
            serveISE(w)
            return
        }
    }

    if !flag.Parsed() {
        flag.Parse()
    }
    if *authDisabled {
        glog.Infof("-disabled_auth is set, not checking credentials\n")
    } else {
        fn = googleauth.RequireLogin(fn)
    }
    return fn
}

开发者ID:mehulsbhatt,项目名称:dashboard-3,代码行数:28,代码来源:router.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng