config.go (957B)
1 package config 2 3 import ( 4 _ "embed" 5 "encoding/json" 6 "flag" 7 "fmt" 8 ) 9 10 var ( 11 //go:embed config.json 12 configuration []byte 13 14 attachment = flag.String("a", "", "attachment path") 15 from = flag.String("f", "", "sender address") 16 subject = flag.String("s", "", "subject") 17 text = flag.String("m", "", "message text") 18 to = flag.String("t", "", "recipient address, comma delimited") 19 ) 20 21 type Config struct { 22 Attachment string 23 From string 24 Pass string 25 Subject string 26 Text string 27 To string 28 User string 29 } 30 31 func New() (*Config, error) { 32 flag.Parse() 33 34 var cfg = &Config{ 35 Attachment: *attachment, 36 From: *from, 37 Subject: *subject, 38 Text: *text, 39 To: *to, 40 } 41 // Load the username and password from the embedded configuration. 42 if err := json.Unmarshal(configuration, cfg); err != nil { 43 return nil, fmt.Errorf("failed to parse config file: %v", err) 44 } 45 46 return cfg, nil 47 }