Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Pointer structs not created with env prefixes #234

Closed
@mrsimonemms

Description

@mrsimonemms

Following the issue raised in#202, if a pointer struct is used then the default object is not created - this is different to a non-pointer object. See the following example:

package mainimport ("encoding/json""fmt""log""os""github.com/caarlos0/env/v6")typeTeststruct {Strstring`env:"TEST"`}typeComplexConfigstruct {Foo*Test`envPrefix:"FOO_"`BarTest`envPrefix:"BAR_"`Clean*Test}funcmain() {os.Setenv("FOO_TEST","kek")os.Setenv("BAR_TEST","lel")cfg:=ComplexConfig{}err:=env.Parse(&cfg)iferr!=nil {log.Fatal(err)}confBytes,_:=json.Marshal(cfg)fmt.Printf("%s",confBytes)}

This results in:

{"Foo":null,"Bar":{"Str":"lel"},"Clean":null}

Notice howFoo isnull, butBar has the object created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp