commit fe4bda3d57a57fb616b9e6c68a13f4c8121eb4df Author: Jay Date: Tue May 7 17:48:58 2019 +0800 add first diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8cf93b5 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module git.trj.tw/golang/go-ddns-client + +go 1.12 + +require git.trj.tw/golang/utils v0.0.0-20190225142552-b019626f0349 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..37994ad --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +git.trj.tw/golang/utils v0.0.0-20190225142552-b019626f0349 h1:V6ifeiJ3ExnjaUylTOz37n6z5uLwm6fjKjnztbTCaQI= +git.trj.tw/golang/utils v0.0.0-20190225142552-b019626f0349/go.mod h1:yE+qbsUsijCTdwsaQRkPT1CXYk7ftMzXsCaaYx/0QI0= diff --git a/main.go b/main.go new file mode 100644 index 0000000..50e8d8d --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("vim-go") +} diff --git a/module/config/config.go b/module/config/config.go new file mode 100644 index 0000000..205fc71 --- /dev/null +++ b/module/config/config.go @@ -0,0 +1,50 @@ +package config + +import ( + "errors" + "os" + "path" + + "git.trj.tw/golang/utils" +) + +// RecordData - +type RecordData struct { + Name string `yaml:"name"` + Type string `yaml:"type"` +} + +// DomainData - +type DomainData struct { + Name string `yaml:"name"` + Records []RecordData `yaml:"records"` +} + +// Config - +type Config struct { + URL string `yaml:"url"` + VerifyValue string `yaml:"verify_value"` + Domains []DomainData `yaml:"domains"` +} + +// LoadConfig - +func LoadConfig(p ...string) error { + var fp string + // set config path + if len(p) > 0 && len(p[0]) > 0 { + fp = p[0] + } else { + wd, err := os.Getwd() + if err != nil { + return err + } + + fp = path.Join(wd, "config.yml") + } + + if exists := utils.CheckExists(fp, false); !exists { + return errors.New("config file not exists") + } + + return nil +}