8000 Values not saved with Must... methods · Issue #45 · go-ini/ini · GitHub
[go: up one dir, main page]

Skip to content

Values not saved with Must... methods #45

Closed

Description

@vadeva

When saving with ini.saveTo() the target file is created or replaced succesfully. However, it contains proper section names and keys, but all the values are missing.

I have verified the values contain data by performing fmt.Printf output right before calling ini.saveTo()

Platform: Go 1.6.1, Mac OS 10.11.4

This is how the contents look like:
2016-04-27 18 02 05

Activity

  1. vadeva commented on Apr 27, 2016

    @vadeva
    Author

    I have found the reason, sorry.

    The ini.Key([key_name]).Must*([default_value]) methods do NOT set the value of the key to the default one passed.

    Such behaviour is very inobvious...

    1. ini.Key([key_name]) creates the key if it does not exist
    2. However, the default value is not set with a Must* method.
      One ends up with an always existing key, but it may have no value!

    Probably, it may be a good idea to provide a method like
    func (s *Section) GuaranteeKey(key, defaultValue string) *Key

    1. If the key does not exist it is created and the default value is assigned
    2. The method returns either the prexisting key or the newly created one
  2. unknwon commented on Jun 29, 2016

    @unknwon
    Member
    1. However, the default value is not set with a Must* method.
      One ends up with an always existing key, but it may have no value!

    Good point!

  3. changed the title [-]Values not saved with «ini.SaveTo(iniFilePath string)»[/-] [+]Values not saved with Must... methods[/+] on Jun 29, 2016
  4. added a commit that references this issue on Jun 29, 2016
  5. unknwon commented on Jun 29, 2016

    @unknwon
    Member

    Changes pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0