update
This commit is contained in:
parent
fe4bda3d57
commit
f828db0a38
7
config.default.yml
Normal file
7
config.default.yml
Normal file
@ -0,0 +1,7 @@
|
||||
url: ''
|
||||
verify_value: ''
|
||||
domains:
|
||||
- name: ''
|
||||
records:
|
||||
- name: ''
|
||||
type: 'A or AAAA'
|
5
go.mod
5
go.mod
@ -2,4 +2,7 @@ module git.trj.tw/golang/go-ddns-client
|
||||
|
||||
go 1.12
|
||||
|
||||
require git.trj.tw/golang/utils v0.0.0-20190225142552-b019626f0349
|
||||
require (
|
||||
git.trj.tw/golang/utils v0.0.0-20190225142552-b019626f0349
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
)
|
||||
|
3
go.sum
3
go.sum
@ -1,2 +1,5 @@
|
||||
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=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
19
main.go
19
main.go
@ -1,7 +1,22 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.trj.tw/golang/go-ddns-client/module/config"
|
||||
"git.trj.tw/golang/go-ddns-client/module/option"
|
||||
)
|
||||
|
||||
func init() {
|
||||
option.RegOptions()
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
var err error
|
||||
opts := option.GetOptions()
|
||||
|
||||
err = config.LoadConfig(opts.Config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"git.trj.tw/golang/utils"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// RecordData -
|
||||
@ -27,6 +29,8 @@ type Config struct {
|
||||
Domains []DomainData `yaml:"domains"`
|
||||
}
|
||||
|
||||
var conf *Config
|
||||
|
||||
// LoadConfig -
|
||||
func LoadConfig(p ...string) error {
|
||||
var fp string
|
||||
@ -42,9 +46,23 @@ func LoadConfig(p ...string) error {
|
||||
fp = path.Join(wd, "config.yml")
|
||||
}
|
||||
|
||||
fp = utils.ParsePath(fp)
|
||||
if exists := utils.CheckExists(fp, false); !exists {
|
||||
return errors.New("config file not exists")
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
conf = &Config{}
|
||||
err = yaml.Unmarshal(data, conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetConfig -
|
||||
func GetConfig() *Config { return conf }
|
||||
|
23
module/option/option.go
Normal file
23
module/option/option.go
Normal file
@ -0,0 +1,23 @@
|
||||
package option
|
||||
|
||||
import "flag"
|
||||
|
||||
// Options -
|
||||
type Options struct {
|
||||
Help bool
|
||||
Config string
|
||||
}
|
||||
|
||||
var opts *Options
|
||||
|
||||
// RegOptions -
|
||||
func RegOptions() {
|
||||
opts = &Options{}
|
||||
flag.StringVar(&opts.Config, "config", "", "config file path - default: `pwd/config.yml`")
|
||||
flag.StringVar(&opts.Config, "f", "", "config file path - default: `pwd/config.yml`")
|
||||
flag.BoolVar(&opts.Help, "help", false, "show help")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
// GetOptions -
|
||||
func GetOptions() *Options { return opts }
|
Loading…
Reference in New Issue
Block a user