Documentation ¶
Overview ¶
Package config consists of main functionality for working with all configuration constants and initialisation struct.
Priority:
OS ENV
Flags
default values
Example (ConfigOrder) ¶
package main import ( "fmt" "os" "github.com/KusoKaihatsuSha/tray_helper/internal/config" "github.com/KusoKaihatsuSha/tray_helper/internal/helpers" ) func main() { testDataFlag := `{ "address": "http://file-flag" }` testDataEnv := `{ "address": "http://file-env" }` fileFlag := helpers.CreateTmp() err := os.WriteFile(fileFlag, []byte(testDataFlag), 0755) if err != nil { fmt.Println(err) } fileEnv := helpers.CreateTmp() err = os.WriteFile(fileEnv, []byte(testDataEnv), 0755) if err != nil { fmt.Println(err) } err = os.Setenv("ADDRESS", "http://env") if err != nil { fmt.Println(err) } err = os.Setenv("CONFIG", fileEnv) if err != nil { fmt.Println(err) } os.Args = append( os.Args, "-config="+fileFlag, "-a=http://flag", ) testConfiguration := config.Init() testConfiguration.Init() testConfiguration.Flag() // preload testConfiguration.Env() // preload // test section testConfiguration.Conf() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Flag() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Env() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Conf() testConfiguration.Flag() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Conf() testConfiguration.Env() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Flag() testConfiguration.Env() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Conf() testConfiguration.Flag() testConfiguration.Env() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Flag() testConfiguration.Conf() testConfiguration.Env() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Conf() testConfiguration.Env() testConfiguration.Flag() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Env() testConfiguration.Conf() testConfiguration.Flag() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Flag() testConfiguration.Env() // last filepath config here testConfiguration.Conf() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) testConfiguration.Env() testConfiguration.Flag() // last filepath config here testConfiguration.Conf() // <-- testConfiguration.Valid() fmt.Println(testConfiguration.Address) helpers.DeleteTmp(fileEnv) helpers.DeleteTmp(fileFlag) }
Output: file-env:80 flag:80 env:80 flag:80 env:80 env:80 env:80 env:80 flag:80 flag:80 file-env:80 file-flag:80
Index ¶
Examples ¶
Constants ¶
View Source
const ( DefTimePostfix = "s" HTTPString = `http://` HTTPSString = `https://` RealIPName = "X-Real-IP" IcoNotif = `icons/notif.ico` IcoApp = `icons/icon.ico` IcoSettings = `icons/settings.ico` IcoClose = `icons/close.ico` Title = "Easy tray helper" ToolTip = "<" + Title + "> make you the daily work some easy" Repeat = "repeat" Silent = "silent" WaitUntilClose = "timer" EmulateAction = "actions" )
General annotation.
Variables ¶
View Source
var EmbedFiles embed.FS
Functions ¶
func SettingsFile ¶
SettingsFile return map[string]any from the setting file
Types ¶
type Configuration ¶
type Configuration struct { PrefixURL string Tmp ConfigurationMain }
Configuration consist settings, which filling on the start. valid list:
"tmp_file" - Crop prefix path and add tmp path for windows. For linux same string "file" - Check exist and return correct /\ "url" - Check correct URL "bool" - Check correct bool "timer" - Check correct timer. If not included "s"... suffix "-", "none" - Nothing to do. Same string
func (*Configuration) Conf ¶
func (c *Configuration) Conf()
Conf get info from the configuration file
func (*Configuration) Dummy ¶
func (c *Configuration) Dummy()
Dummy needed for the default printing of Flags info
func (*Configuration) Valid ¶
func (c *Configuration) Valid()
Valid check info and make some correcting
type ConfigurationMain ¶
type ConfigurationMain struct { Config string `json:"config" default:"settings.data" flag:"f,c,config" env:"CONFIG" text:"Config file" valid:"file"` Ico string `json:"ico_file" default:"app.ico" flag:"ico" env:"ICO_FILE" text:"Filepath for ico notif" valid:"tmp_file"` Address string `json:"address" default:"ip:0" flag:"a" env:"ADDRESS" text:"Address and port" valid:"url"` }
ConfigurationMain - block consist the main settings
Click to show internal directories.
Click to hide internal directories.