MCPcopy Create free account
hub / github.com/opencloud-eu/opencloud / ExampleDecode

Function ExampleDecode

pkg/config/envdecode/envdecode_test.go:452–478  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

450}
451
452func ExampleDecode() {
453 type Example struct {
454 // A string field, without any default
455 String string `env:"EXAMPLE_STRING"`
456
457 // A uint16 field, with a default value of 100
458 Uint16 uint16 `env:"EXAMPLE_UINT16,default=100"`
459 }
460
461 os.Setenv("EXAMPLE_STRING", "an example!")
462
463 var e Example
464 if err := Decode(&e); err != nil {
465 panic(err)
466 }
467
468 // If TEST_STRING is set, e.String will contain its value
469 fmt.Println(e.String)
470
471 // If TEST_UINT16 is set, e.Uint16 will contain its value.
472 // Otherwise, it will contain the default value, 100.
473 fmt.Println(e.Uint16)
474
475 // Output:
476 // an example!
477 // 100
478}
479
480//// Export tests
481

Callers

nothing calls this directly

Calls 1

DecodeFunction · 0.85

Tested by

no test coverage detected