本文整理汇总了Golang中github.com/spf13/viper.Set函数的典型用法代码示例。如果您正苦于以下问题:Golang Set函数的具体用法?Golang Set怎么用?Golang Set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetupSuite
func (suite *HelpCommandTestSuite) SetupSuite() {
DJ = bot.NewMumbleDJ()
viper.Set("commands.help.aliases", []string{"help", "h"})
viper.Set("commands.help.description", "help")
viper.Set("commands.help.is_admin", false)
}
示例2: SetupSuite
func (suite *CacheSizeCommandTestSuite) SetupSuite() {
DJ = bot.NewMumbleDJ()
viper.Set("commands.cachesize.aliases", []string{"cachesize", "cs"})
viper.Set("commands.cachesize.description", "cachesize")
viper.Set("commands.cachesize.is_admin", true)
}
示例3: server
func server(cmd *cobra.Command, args []string) {
InitializeConfig()
if cmd.Flags().Lookup("disableLiveReload").Changed {
viper.Set("DisableLiveReload", disableLiveReload)
}
if serverWatch {
viper.Set("Watch", true)
}
if viper.GetBool("watch") {
serverWatch = true
}
l, err := net.Listen("tcp", net.JoinHostPort(serverInterface, strconv.Itoa(serverPort)))
if err == nil {
l.Close()
} else {
jww.ERROR.Println("port", serverPort, "already in use, attempting to use an available port")
sp, err := helpers.FindAvailablePort()
if err != nil {
jww.ERROR.Println("Unable to find alternative port to use")
jww.ERROR.Fatalln(err)
}
serverPort = sp.Port
}
viper.Set("port", serverPort)
BaseURL, err := fixURL(BaseURL)
if err != nil {
jww.ERROR.Fatal(err)
}
viper.Set("BaseURL", BaseURL)
if err := memStats(); err != nil {
jww.ERROR.Println("memstats error:", err)
}
build(serverWatch)
// Watch runs its own server as part of the routine
if serverWatch {
watched := getDirList()
workingDir := helpers.AbsPathify(viper.GetString("WorkingDir"))
for i, dir := range watched {
watched[i], _ = helpers.GetRelativePath(dir, workingDir)
}
unique := strings.Join(helpers.RemoveSubpaths(watched), ",")
jww.FEEDBACK.Printf("Watching for changes in %s/{%s}\n", workingDir, unique)
err := NewWatcher(serverPort)
if err != nil {
fmt.Println(err)
}
}
serve(serverPort)
}
示例4: initConfig
// initConfig reads in config file and ENV variables if set.
func initConfig(cmd *cobra.Command) {
viper.SetConfigName(".skelly") // name of config file (without extension)
viper.AddConfigPath("$HOME") // adding home directory as first search path
viper.SetConfigType("json")
viper.AutomaticEnv() // read in environment variables that match
fmt.Println("got here")
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
// Make sure that go src var is set
gopath = viper.GetString("gopath")
if len(gopath) <= 0 {
gopath = joinPath(os.Getenv("GOPATH"), "src")
viper.Set("gopath", gopath)
}
if cmd.Flags().Lookup("project-root").Changed {
viper.Set("project-root", basePath)
}
if cmd.Flags().Lookup("author").Changed {
fmt.Println("adding author")
viper.Set("author", author)
}
if cmd.Flags().Lookup("email").Changed {
viper.Set("email", email)
}
fmt.Println(email)
if cmd.Flags().Lookup("license").Changed {
viper.Set("license", license)
}
}
示例5: TestPageCount
func TestPageCount(t *testing.T) {
testCommonResetState()
hugofs.InitMemFs()
viper.Set("uglyURLs", false)
viper.Set("paginate", 10)
s := &Site{
Source: &source.InMemorySource{ByteSource: urlFakeSource},
Language: helpers.NewDefaultLanguage(),
}
if err := buildAndRenderSite(s, "indexes/blue.html", indexTemplate); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
_, err := hugofs.Destination().Open("public/blue")
if err != nil {
t.Errorf("No indexed rendered.")
}
for _, s := range []string{
"public/sd1/foo/index.html",
"public/sd2/index.html",
"public/sd3/index.html",
"public/sd4.html",
} {
if _, err := hugofs.Destination().Open(filepath.FromSlash(s)); err != nil {
t.Errorf("No alias rendered: %s", s)
}
}
}
示例6: setRomanaRootURL
// setRomanaRootURL sanitizes rootURL and rootPort and also
// sets baseURL which is needed to connect to other romana
// services.
func setRomanaRootURL() {
// Variables used for configuration and flags.
var baseURL string
var rootURL string
var rootPort string
// Add port details to rootURL else try localhost
// if nothing is given on command line or config.
rootURL = config.GetString("RootURL")
rootPort = config.GetString("RootPort")
if rootPort == "" {
re, _ := regexp.Compile(`:\d+/?`)
port := re.FindString(rootURL)
port = strings.TrimPrefix(port, ":")
port = strings.TrimSuffix(port, "/")
if port != "" {
rootPort = port
} else {
rootPort = "9600"
}
}
config.Set("RootPort", rootPort)
if rootURL != "" {
baseURL = strings.TrimSuffix(rootURL, "/")
baseURL = strings.TrimSuffix(baseURL, ":9600")
baseURL = strings.TrimSuffix(baseURL, ":"+rootPort)
} else {
baseURL = "http://localhost"
}
config.Set("BaseURL", baseURL)
rootURL = baseURL + ":" + rootPort + "/"
config.Set("RootURL", rootURL)
}
示例7: TestRelURL
func TestRelURL(t *testing.T) {
defer viper.Reset()
//defer viper.Set("canonifyURLs", viper.GetBool("canonifyURLs"))
tests := []struct {
input string
baseURL string
canonify bool
expected string
}{
{"/test/foo", "http://base/", false, "/test/foo"},
{"test.css", "http://base/sub", false, "/sub/test.css"},
{"test.css", "http://base/sub", true, "/test.css"},
{"/test/", "http://base/", false, "/test/"},
{"/test/", "http://base/sub/", false, "/sub/test/"},
{"/test/", "http://base/sub/", true, "/test/"},
{"", "http://base/ace/", false, "/ace/"},
{"", "http://base/ace", false, "/ace"},
{"http://abs", "http://base/", false, "http://abs"},
{"//schemaless", "http://base/", false, "//schemaless"},
}
for i, test := range tests {
viper.Reset()
viper.Set("BaseURL", test.baseURL)
viper.Set("canonifyURLs", test.canonify)
output := RelURL(test.input)
if output != test.expected {
t.Errorf("[%d][%t] Expected %#v, got %#v\n", i, test.canonify, test.expected, output)
}
}
}
示例8: TestReadPagesFromSourceWithEmptySource
// Issue #1797
func TestReadPagesFromSourceWithEmptySource(t *testing.T) {
viper.Reset()
defer viper.Reset()
viper.Set("DefaultExtension", "html")
viper.Set("verbose", true)
viper.Set("baseurl", "http://auth/bub")
sources := []source.ByteSource{}
s := &Site{
Source: &source.InMemorySource{ByteSource: sources},
targets: targetList{page: &target.PagePub{UglyURLs: true}},
}
var err error
d := time.Second * 2
ticker := time.NewTicker(d)
select {
case err = <-s.ReadPagesFromSource():
break
case <-ticker.C:
err = fmt.Errorf("ReadPagesFromSource() never returns in %s", d.String())
}
ticker.Stop()
if err != nil {
t.Fatalf("Unable to read source: %s", err)
}
}
示例9: SetupSuite
func (suite *ToggleShuffleCommandTestSuite) SetupSuite() {
DJ = bot.NewMumbleDJ()
viper.Set("commands.toggleshuffle.aliases", []string{"toggleshuffle", "ts"})
viper.Set("commands.toggleshuffle.description", "toggleshuffle")
viper.Set("commands.toggleshuffle.is_admin", true)
}
示例10: cmdSetup
func cmdSetup(c *cli.Context) {
token := c.Args().First()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := qiita.NewClient(tc)
user, err := client.AuthenticatedUser.Show()
if err != nil {
fmt.Println("Auth failed")
os.Exit(1)
}
loadConfig()
viper.Set("accessToken", token)
viper.Set("id", user.Id)
err = saveConfig()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Token saved")
}
示例11: TestRobotsTXTOutput
func TestRobotsTXTOutput(t *testing.T) {
testCommonResetState()
hugofs.InitMemFs()
viper.Set("baseurl", "http://auth/bub/")
viper.Set("enableRobotsTXT", true)
s := &Site{
Source: &source.InMemorySource{ByteSource: weightedSources},
Language: helpers.NewDefaultLanguage(),
}
if err := buildAndRenderSite(s, "robots.txt", robotTxtTemplate); err != nil {
t.Fatalf("Failed to build site: %s", err)
}
robotsFile, err := hugofs.Destination().Open("public/robots.txt")
if err != nil {
t.Fatalf("Unable to locate: robots.txt")
}
robots := helpers.ReaderToBytes(robotsFile)
if !bytes.HasPrefix(robots, []byte("User-agent: Googlebot")) {
t.Errorf("Robots file should start with 'User-agentL Googlebot'. %s", robots)
}
}
示例12: InitializeConfig
// InitializeConfig initializes a config file with sensible default configuration flags.
func InitializeConfig() {
viper.SetConfigName("grasshopper") // name of config file (without extension)
viper.AddConfigPath("/etc/grasshopper.d/") // path to look for the config file
viper.AddConfigPath("$HOME/.grasshopper.d") // call multiple times to add many search paths
viper.AddConfigPath(".") // optionally look for config in the working directory
// read config from storage
err := viper.ReadInConfig() // FIXME
if err != nil {
jww.INFO.Println("Unable to locate Config file. I will fall back to my defaults...")
}
// default settings
viper.SetDefault("Verbose", false)
viper.SetDefault("DryRun", false)
viper.SetDefault("DoLog", true)
// bind config to command flags
if grasshopperCmdV.PersistentFlags().Lookup("verbose").Changed {
viper.Set("Verbose", Verbose)
}
if grasshopperCmdV.PersistentFlags().Lookup("log").Changed {
viper.Set("DoLog", DoLog)
}
}
示例13: main
func main() {
viper.Set("version", version)
viper.Set("gitBranch", gitBranch)
viper.Set("gitCommit", gitCommit)
viper.Set("buildDate", buildDate)
cmd.Execute()
}
示例14: msgBuffer
func msgBuffer() {
params := &sqs.ReceiveMessageInput{
QueueUrl: aws.String(viper.GetString("URL") + ID),
AttributeNames: []*string{
aws.String("All"),
},
MaxNumberOfMessages: aws.Int64(10),
MessageAttributeNames: []*string{
aws.String("Dest." + ID),
},
VisibilityTimeout: aws.Int64(1),
}
resp, err := svc.ReceiveMessage(params)
errHandle(err)
for _, element := range resp.Messages {
var m Message
data, _ := strconv.Unquote(awsutil.Prettify(element.Body))
b := []byte(data)
err := json.Unmarshal(b, &m)
errHandle(err)
//This is where we will send the message to the queue for the service
viper.Set("Dest", m.Dest)
viper.Set("Sender", m.Sender)
go execute(m)
//If all goes well, the message has been forwarded to the responsible queue
deleteMsg(element)
}
}
示例15: InitializeCertAuthConfig
// InitializeCertAuthConfig sets up the command line options for creating a CA
func InitializeCertAuthConfig(logger log.Logger) error {
viper.SetDefault("Bits", "4096")
viper.SetDefault("Years", "10")
viper.SetDefault("Organization", "kappa-ca")
viper.SetDefault("Country", "USA")
if initCmd.PersistentFlags().Lookup("bits").Changed {
logger.Info("", "Bits", KeyBits)
viper.Set("Bits", KeyBits)
}
if initCmd.PersistentFlags().Lookup("years").Changed {
logger.Info("", "Years", Years)
viper.Set("Years", Years)
}
if initCmd.PersistentFlags().Lookup("organization").Changed {
logger.Info("", "Organization", Organization)
viper.Set("Organization", Organization)
}
if initCmd.PersistentFlags().Lookup("country").Changed {
logger.Info("", "Country", Country)
viper.Set("Country", Country)
}
if initCmd.PersistentFlags().Lookup("hosts").Changed {
logger.Info("", "Hosts", Hosts)
viper.Set("Hosts", Hosts)
}
return nil
}