Skip to content

Commit

Permalink
docs(example): code example (#51)
Browse files Browse the repository at this point in the history
See the issue for details
- Documentations #15
  • Loading branch information
rasatmaja authored Aug 18, 2021
1 parent 186bbf6 commit db11dbb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"encoding/json"
"fmt"

"github.com/rasatmaja/mura/v2"
)

// Config ...
type Config struct {
Host string `env:"SERVER_HOST" default:"localhost"`
Port int `env:"SERVER_PORT" default:"8080"`
TLS bool `env:"SERVER_TLS" default:"true"`
}

func main() {
cfg := new(Config)

err := mura.Unmarshal(cfg)
if err != nil {
panic(err)
}

print(cfg)
}

func print(i interface{}) {
s, _ := json.MarshalIndent(i, "", "\t")
fmt.Println("============== ENV ==============")
fmt.Printf("%s \n", s)
fmt.Println("=================================")
}

0 comments on commit db11dbb

Please sign in to comment.