Skip to content

Commit

Permalink
Added config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
JCoupalK committed Dec 23, 2023
1 parent 44cdfb5 commit bec8123
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 285 deletions.
66 changes: 33 additions & 33 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package main

import (
"encoding/json"
"os"
)

// For config file
type Config struct {
SMTPServer string `json:"smtp_server"`
SMTPPort int `json:"smtp_port"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
FromEmail string `json:"from_email"`
}

func loadConfig(filePath string) (Config, error) {
var config Config

file, err := os.Open(filePath)
if err != nil {
return config, err
}
defer file.Close()

decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
return config, err
}

return config, nil
}
package main

import (
"encoding/json"
"os"
)

// For config file
type Config struct {
SMTPServer string `json:"smtp_server"`
SMTPPort int `json:"smtp_port"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
FromEmail string `json:"from_email"`
}

func loadConfig(filePath string) (Config, error) {
var config Config

file, err := os.Open(filePath)
if err != nil {
return config, err
}
defer file.Close()

decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
return config, err
}

return config, nil
}
Loading

0 comments on commit bec8123

Please sign in to comment.