Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

golang json time

package main

import (
	"log"

	"github.com/catamat/config"
)

type configJSON struct {
	Word   string `json:"word"`
	Number int    `json:"number"`
	Check  bool   `json:"check"`
	Slice  []int  `json:"myslice"`
}

type configEnv struct {
	TmpDir      string `env:"TMPDIR"`
	HOME        string
	Shell       string `env:"SHELL"`
	User        string `env:"USER"`
	GoRoot      string `env:"GOROOT"`
	CgoCflags   string `env:"CGO_CFLAGS"`
	VscodePid   int    `env:"VSCODE_PID"`
	PipeLogging bool   `env:"PIPE_LOGGING"`
	Slice       []int  `env:"MY_SLICE" vsep:":"`
}

type configFlags struct {
	Word   string `flag:"-word"`
	Number int    `flag:"-number"`
	Check  bool   `flag:"-check"`
	Slice  []int  `flag:"-myslice" vsep:","`
}

func main() {
	/*
	    {
	        "word": "TestWord",
	        "number": 123456,
	        "check": true,
	        "myslice": [1,1,2,3,5,8]
	    }
	*/
	log.Println("JSON:")
	cfg1 := configJSON{}
	config.FromJSON(&cfg1, "config.json")
	log.Println(cfg1)

	/*
	    os.Setenv("MY_SLICE", "111:222:333")
	*/
	log.Println("Env:")
	cfg2 := configEnv{}
	config.FromEnv(&cfg2)
	log.Println(cfg2)

	/*
	    ./example -word=TestWord -number=123456 -check=true -myslice=1,1,2,3,5,8
	*/
	log.Println("Flags:")
	cfg3 := configFlags{}
	config.FromFlags(&cfg3)
	log.Println(cfg3)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js hide modal event listener name 
Javascript :: used as a function, Number() will convert another value 
Javascript :: set style javascript and cancel it to use default 
Javascript :: material ui table row onclick 
Javascript :: image opacity reduce js 
Javascript :: unique elements 
Javascript :: documetn 
Javascript :: expo google sign inredirect uri mismatch 
Javascript :: tampermonkey all pages 
Javascript :: django formdata use csrf token in js 
Javascript :: what is the maximum x value of a window for mouse listener 
Javascript :: reuse jquery angular 
Javascript :: javascript string is mutable 
Javascript :: How to get only property names/keys from a nested object 
Javascript :: jquery console.log object file 
Javascript :: rest framework and json 
Javascript :: javascript remove files name starts with 
Javascript :: react Update a label when rate moves "quietly" 
Javascript :: dsicrod.js bot answer to himself 
Javascript :: javascript compare dates old new value 
Javascript :: discord javascript error on startup 
Javascript :: hide react from netlify 
Javascript :: string to number javascript & remove text 
Javascript :: filter-vs-map-reactjs-and-jsx 
Javascript :: visio prevent arrows from snapping 
Javascript :: Scratch Addon userscript 
Javascript :: react hooks link to external site new tab 
Javascript :: react-native-error-check-the-render-method-of-app 
Javascript :: read url jsf 
Javascript :: asynchronous file read 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =