當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mergo.MergeWithOverwrite函數代碼示例

本文整理匯總了Golang中github.com/imdario/mergo.MergeWithOverwrite函數的典型用法代碼示例。如果您正苦於以下問題:Golang MergeWithOverwrite函數的具體用法?Golang MergeWithOverwrite怎麽用?Golang MergeWithOverwrite使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MergeWithOverwrite函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getAttributes

func getAttributes(keys []string, overwriteAttributes map[string]interface{}) (map[string]interface{}, error) {
	var attributes map[string]interface{}
	var c *api.Client = util.Consul()
	attributes = make(map[string]interface{})

	//	Get attributes from consul KVS
	for _, key := range keys {
		list, _, err := c.KV().List(key, &api.QueryOptions{})
		if err != nil {
			return nil, err
		}

		for _, kv := range list {
			var a map[string]interface{}
			if err := json.Unmarshal(kv.Value, &a); err != nil {
				return nil, err
			}
			if err := mergo.MergeWithOverwrite(&attributes, a); err != nil {
				return nil, errors.New(fmt.Sprintf("Failed to merge attributes(%v)", err))
			}
		}
	}

	//	Overwrite some attributes by specified parameter in task.yml
	if err := mergo.MergeWithOverwrite(&attributes, overwriteAttributes); err != nil {
		return nil, err
	}
	return attributes, nil
}
開發者ID:cloudconductor,項目名稱:metronome,代碼行數:29,代碼來源:chef.go

示例2: loadConfigFile

func loadConfigFile(o *Options) {
	isDefault := false
	configPath := o.ConfigFile
	if o.ConfigFile == "" {
		isDefault = true
		configPath = "./deploy.yaml"
	}

	data, err := ioutil.ReadFile(configPath)
	if err != nil {
		if os.IsNotExist(err) && isDefault {
			return
		}

		panic(err)
	}

	var file ConfigFile
	err = yaml.Unmarshal(data, &file)
	panicIf(err)

	var envCfg Options
	if o.Env != "" {
		var ok bool
		envCfg, ok = file[o.Env]
		if !ok {
			panic("Config for specified env not found")
		}
	}

	defCfg, _ := file["default"]

	panicIf(mergo.MergeWithOverwrite(o, defCfg))
	panicIf(mergo.MergeWithOverwrite(o, envCfg))
}
開發者ID:tomisme,項目名稱:Stout,代碼行數:35,代碼來源:utils.go

示例3: Load

// Load loads the configuration from a yaml file
func (c *Config) Load(file string) error {
	data, err := ioutil.ReadFile(file)

	if err != nil {
		log.Printf("Unable to ReadConfig File: %s -> %s", file, err.Error())
		return err
	}

	conf := Config{}
	err = yaml.Unmarshal(data, &conf)

	if err != nil {
		log.Printf("Unable to load Config File: %s -> %s", file, err.Error())
		return err
	}

	if err := mergo.MergeWithOverwrite(c, conf); err != nil {
		return err
	}

	c.Env = strings.TrimSpace(c.Env)

	env := strings.ToLower(c.Env)

	if !strings.Contains(env, "dev") && !strings.Contains(env, "development") && !strings.Contains(env, "debug") {
		c.Mode = 1
	}

	return nil
}
開發者ID:influx6,項目名稱:relay,代碼行數:31,代碼來源:engine.go

示例4: TestSetGetConfigSuccess

func (s *SystemTestSuite) TestSetGetConfigSuccess(c *C) {
	// read current config, to prepare the test config with just ansible changes
	cmdStr := `clusterctl config get --json`
	out, err := s.tbn1.RunCommandWithOutput(cmdStr)
	s.Assert(c, err, IsNil, Commentf("output: %s", out))
	var config map[string]interface{}
	err = json.Unmarshal([]byte(out), &config)
	s.Assert(c, err, IsNil)
	var testConfig map[string]interface{}
	err = json.Unmarshal([]byte(`{
    "ansible": {
        "playbook_location":  "foo"
    }
}`), &testConfig)
	s.Assert(c, err, IsNil)
	err = mergo.MergeWithOverwrite(&config, &testConfig)
	s.Assert(c, err, IsNil)
	configStr, err := json.Marshal(config)
	s.Assert(c, err, IsNil)

	c.Logf("config: %+v", config)
	c.Logf("json: %q", configStr)
	cmdStr = fmt.Sprintf(`clusterctl config set - <<EOF
%s
EOF`, configStr)
	out, err = s.tbn1.RunCommandWithOutput(cmdStr)
	s.Assert(c, err, IsNil, Commentf("output: %s", out))
	cmdStr = `clusterctl config get --json`
	out, err = s.tbn1.RunCommandWithOutput(cmdStr)
	s.Assert(c, err, IsNil, Commentf("output: %s", out))
	exptdOut := `.*"playbook_location":.*"foo".*`
	s.assertMatch(c, exptdOut, out)
}
開發者ID:contiv,項目名稱:cluster,代碼行數:33,代碼來源:clusterctl_test.go

示例5: AddDebt

func (p *Player) AddDebt(d Debt) error {
	newDebt := new(Debt)
	if err := mergo.MergeWithOverwrite(newDebt, d); err != nil {
		return errors.New(err.Error() + " - Could not set Debt data")
	}
	newDebt.UUID, _ = uuid.V4()
	if d.Created.IsZero() {
		newDebt.Created = time.Now()
	} else {
		newDebt.Created = d.Created
	}
	if !d.Settled.IsZero() {
		newDebt.Settled = d.Settled
	}
	newDebt.Debitor = p.UUID
	p.Debts = append(p.Debts, *newDebt)
	err := storage.Store(p)
	if err != nil {
		return errors.New("Could not add debt")
	}
	eventqueue.Publish(utils.CKPTEvent{
		Type:         utils.PLAYER_EVENT,
		RestrictedTo: []uuid.UUID{p.UUID},
		Subject:      "Gjeld registrert",
		Message:      "Det er registrert et nytt gjeldskrav mot deg på ckpt.no!"})
	return nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:27,代碼來源:players.go

示例6: SetVotes

func (p *Player) SetVotes(v Votes) error {
	if err := mergo.MergeWithOverwrite(&p.Votes, v); err != nil {
		return errors.New(err.Error() + " - Could not set Votes data")
	}
	err := storage.Store(p)
	if err != nil {
		return errors.New("Could not set votes")
	}
	return nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:10,代碼來源:players.go

示例7: UpdateProfile

func (l *Location) UpdateProfile(lp Profile) error {
	if err := mergo.MergeWithOverwrite(&l.Profile, lp); err != nil {
		return errors.New(err.Error() + " - Could not update location profile")
	}
	err := storage.Store(l)
	if err != nil {
		return errors.New(err.Error() + " - Could not store updated location profile")
	}
	return nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:10,代碼來源:locations.go

示例8: UpdateInfo

func (c *Catering) UpdateInfo(ci Info) error {
	if err := mergo.MergeWithOverwrite(&c.Info, ci); err != nil {
		return errors.New(err.Error() + " - Could not update catering info")
	}
	err := storage.Store(c)
	if err != nil {
		return errors.New(err.Error() + " - Could not store updated catering info")
	}
	return nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:10,代碼來源:caterings.go

示例9: NewCatering

// Create a Catering
func NewCatering(tournament uuid.UUID, ci Info) (*Catering, error) {
	c := new(Catering)
	c.UUID, _ = uuid.V4()
	c.Tournament = tournament
	if err := mergo.MergeWithOverwrite(&c.Info, ci); err != nil {
		return nil, errors.New(err.Error() + " - Could not set initial catering info")
	}
	if err := storage.Store(c); err != nil {
		return nil, errors.New(err.Error() + " - Could not write catering to storage")
	}
	return c, nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:13,代碼來源:caterings.go

示例10: NewLocation

// Create a Location
func NewLocation(host uuid.UUID, lp Profile) (*Location, error) {
	l := new(Location)
	l.UUID, _ = uuid.V4()
	l.Active = true
	l.Host = host
	if err := mergo.MergeWithOverwrite(&l.Profile, lp); err != nil {
		return nil, errors.New(err.Error() + " - Could not set initial location profile")
	}
	if err := storage.Store(l); err != nil {
		return nil, errors.New(err.Error() + " - Could not write location to storage")
	}
	return l, nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:14,代碼來源:locations.go

示例11: Load

// Load loads the configuration from a yaml file
func (c *BuildConfig) Load(file string) error {
	data, err := ioutil.ReadFile(file)

	if err != nil {
		log.Printf("Unable to ReadConfig File: %s -> %s", file, err.Error())
		return err
	}

	conf := BuildConfig{}
	err = yaml.Unmarshal(data, &conf)

	if err != nil {
		log.Printf("Unable to load Config File: %s -> %s", file, err.Error())
		return err
	}

	if conf.Package == "" {
		return errors.New("package option can not be empty, provide the project package name please")
	}

	if err := mergo.MergeWithOverwrite(c, conf); err != nil {
		return err
	}

	if mano, err := strconv.ParseBool(c.UseMain); err == nil {
		c.GoMain = mano
	}

	if vbo, err := strconv.ParseBool(c.Client.Verbose); err == nil {
		c.Client.UseVerbose = vbo
	}

	if doge, err := strconv.ParseBool(c.DoGoGet); err == nil {
		c.Goget = doge
	}

	c.ClientPackage = filepath.Join(c.Package, "client")

	if strings.Contains(c.ClientPackage, `\`) {
		c.ClientPackage = filepath.ToSlash(c.ClientPackage)
	}

	env := strings.ToLower(c.Env)

	if !strings.Contains(env, "dev") && !strings.Contains(env, "development") && !strings.Contains(env, "debug") {
		c.Mode = 1
	}

	return nil
}
開發者ID:influx6,項目名稱:relay,代碼行數:51,代碼來源:config.go

示例12: Shell

// Shell creates an interactive Docker session to the specified service
// starting it if not currently running
func (c *DockerCompose) Shell(config parity.ShellConfig) (err error) {
	log.Stage("Interactive Shell")
	log.Debug("Compose - starting docker compose services")

	mergedConfig := *parity.DEFAULT_INTERACTIVE_SHELL_OPTIONS
	mergo.MergeWithOverwrite(&mergedConfig, &config)
	// Check if services running

	// TODO: if running, attach to running container
	// if NOT running, start services and attach
	if c.project != nil {
		log.Step("Starting compose services")

		injectDisplayEnvironmentVariables(c.project)
	}

	container := fmt.Sprintf("parity-%s_%s_1", c.pluginConfig.ProjectNameSafe, mergedConfig.Service)

	client := utils.DockerClient()

	createExecOptions := dockerclient.CreateExecOptions{
		AttachStdin:  true,
		AttachStdout: true,
		AttachStderr: true,
		Tty:          true,
		Cmd:          mergedConfig.Command,
		User:         mergedConfig.User,
		Container:    container,
	}

	startExecOptions := dockerclient.StartExecOptions{
		Detach:       false,
		Tty:          true,
		InputStream:  os.Stdin,
		OutputStream: os.Stdout,
		ErrorStream:  os.Stderr,
		RawTerminal:  true,
	}

	log.Step("Attaching to container '%s'", container)
	if id, err := client.CreateExec(createExecOptions); err == nil {
		client.StartExec(id.ID, startExecOptions)
	} else {
		log.Error("error: %v", err.Error())
	}

	log.Debug("Docker Compose Run() finished")
	return err
}
開發者ID:mefellows,項目名稱:parity,代碼行數:51,代碼來源:compose.go

示例13: ApplyDefaults

func (c *Config) ApplyDefaults() {
	// config := defaultConfig

	setDebug := !c.Debug
	var shouldDebug bool
	if setDebug {
		shouldDebug = c.Debug
	}

	mergo.MergeWithOverwrite(c, defaultConfig)

	if setDebug {
		c.Debug = shouldDebug
	}
}
開發者ID:jens-a-e,項目名稱:ginja,代碼行數:15,代碼來源:config.go

示例14: UpdateNewsItem

func (c *NewsItem) UpdateNewsItem(ci NewsItem) error {
	d := new(NewsItem)
	*d = *c
	if err := mergo.MergeWithOverwrite(c, ci); err != nil {
		return errors.New(err.Error() + " - Could not update NewsItem info")
	}
	c.UUID = d.UUID
	c.Author = d.Author
	c.Created = d.Created
	c.Tag = d.Tag
	err := storage.Store(c)
	if err != nil {
		return errors.New(err.Error() + " - Could not store updated NewsItem info")
	}
	return nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:16,代碼來源:news.go

示例15: NewNewsItem

// Create a NewsItem
func NewNewsItem(itemdata NewsItem, author uuid.UUID) (*NewsItem, error) {
	c := new(NewsItem)
	if err := mergo.MergeWithOverwrite(c, itemdata); err != nil {
		return nil, errors.New(err.Error() + " - Could not set initial NewsItem data")
	}
	c.UUID, _ = uuid.V4()
	c.Author = author
	c.Created = time.Now()
	if err := storage.Store(c); err != nil {
		return nil, errors.New(err.Error() + " - Could not write NewsItem to storage")
	}
	eventqueue.Publish(utils.CKPTEvent{
		Type:    utils.NEWS_EVENT,
		Subject: "Nytt bidrag lagt ut",
		Message: "Det er lagt ut et nytt bidrag på ckpt.no!"})
	return c, nil
}
開發者ID:ckpt,項目名稱:backend-services,代碼行數:18,代碼來源:news.go


注:本文中的github.com/imdario/mergo.MergeWithOverwrite函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。