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


Golang auth.FromEnv函数代码示例

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


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

示例1: SetupAuth

// SetupAuth sets the client's authMode. It tries from the environment first if we're on android or in dev mode, and then from the client configuration.
func (c *Client) SetupAuth() error {
	// env var takes precedence, but only if we're in dev mode or on android.
	// Too risky otherwise.
	if android.OnAndroid() || os.Getenv("CAMLI_DEV_CAMLI_ROOT") != "" {
		authMode, err := auth.FromEnv()
		if err == nil {
			c.authMode = authMode
			return nil
		}
		if err != auth.ErrNoAuth {
			return fmt.Errorf("Could not set up auth from env var CAMLI_AUTH: %v", err)
		}
	}
	if c.server == "" {
		return fmt.Errorf("No server defined for this client: can not set up auth.")
	}
	authConf := serverAuth(c.server)
	if authConf == "" {
		c.authErr = fmt.Errorf("could not find auth key for server %q in config, defaulting to no auth", c.server)
		c.authMode = auth.None{}
		return nil
	}
	var err error
	c.authMode, err = auth.FromConfig(authConf)
	return err
}
开发者ID:philsnow,项目名称:camlistore,代码行数:27,代码来源:config.go

示例2: SetupAuthFromConfig

func (c *Client) SetupAuthFromConfig(conf jsonconfig.Obj) (err error) {
	value, ok := conf["auth"]
	authString := ""
	if ok {
		authString, ok = value.(string)
		c.authMode, err = auth.FromConfig(authString)
	} else {
		c.authMode, err = auth.FromEnv()
	}
	return err
}
开发者ID:splade,项目名称:camlistore,代码行数:11,代码来源:config.go

示例3: SetupAuth

// SetupAuth sets the client's authMode from the client
// configuration file or from the environment.
func (c *Client) SetupAuth() error {
	if flagServer != "" {
		// If using an explicit blobserver, don't use auth
		// configured from the config file, so we don't send
		// our password to a friend's blobserver.
		var err error
		c.authMode, err = auth.FromEnv()
		if err == auth.ErrNoAuth {
			log.Printf("Using explicit --server parameter; not using config file auth, and no auth mode set in environment")
		}
		return err
	}
	configOnce.Do(parseConfig)
	var err error
	if config == nil || config.auth == "" {
		c.authMode, err = auth.FromEnv()
	} else {
		c.authMode, err = auth.FromConfig(config.auth)
	}
	return err
}
开发者ID:kamoljan,项目名称:camlistore,代码行数:23,代码来源:config.go

示例4: main

func main() {
	flag.Parse()

	_, err := auth.FromEnv()
	if err != nil {
		log.Fatal(err)
	}

	ws := webserver.New()
	ws.HandleFunc("/", handleRoot)
	ws.HandleFunc("/camli/sig/", handleCamliSig)
	ws.Serve()
}
开发者ID:t3rm1n4l,项目名称:camlistore,代码行数:13,代码来源:camsigd.go

示例5: SetupAuthFromConfig

// SetupAuthFromConfig sets the Client's authMode using the "auth" key in conf
// if found, or the environment otherwise.
func (c *Client) SetupAuthFromConfig(conf jsonconfig.Obj) error {
	// TODO(mpl): leaving this one alone for now because it's used by remote as well.
	// See about converting/removing it later.
	var err error
	value, ok := conf["auth"]
	authString := ""
	if ok {
		authString, ok = value.(string)
		c.authMode, err = auth.FromConfig(authString)
	} else {
		c.authMode, err = auth.FromEnv()
	}
	return err
}
开发者ID:rayleyva,项目名称:camlistore,代码行数:16,代码来源:config.go

示例6: SetupAuth

// SetupAuth sets the client's authMode. It tries from the environment first if we're on android or in dev mode, and then from the client configuration.
func (c *Client) SetupAuth() error {
	if c.paramsOnly {
		if c.authMode != nil {
			if _, ok := c.authMode.(*auth.None); !ok {
				return nil
			}
		}
		return errors.New("client: paramsOnly set; auth should not be configured from config or env vars.")
	}
	// env var takes precedence, but only if we're in dev mode or on android.
	// Too risky otherwise.
	if android.OnAndroid() ||
		env.IsDev() ||
		configDisabled {
		authMode, err := auth.FromEnv()
		if err == nil {
			c.authMode = authMode
			return nil
		}
		if err != auth.ErrNoAuth {
			return fmt.Errorf("Could not set up auth from env var CAMLI_AUTH: %v", err)
		}
	}
	if c.server == "" {
		return fmt.Errorf("No server defined for this client: can not set up auth.")
	}
	authConf := serverAuth(c.server)
	if authConf == "" {
		c.authErr = fmt.Errorf("could not find auth key for server %q in config, defaulting to no auth", c.server)
		c.authMode = auth.None{}
		return nil
	}
	var err error
	c.authMode, err = auth.FromConfig(authConf)
	return err
}
开发者ID:louisyoo,项目名称:camlistore,代码行数:37,代码来源:config.go


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