Refactor debug to dev
This commit is contained in:
parent
d7ed09175c
commit
217aef902b
4 changed files with 18 additions and 8 deletions
16
api/api.go
16
api/api.go
|
@ -34,10 +34,14 @@ type resultResponse struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAPI(c Config) API {
|
// Constructs a new Name.com API
|
||||||
a := API{username: c.Username, token: c.Token}
|
//
|
||||||
|
// If dev = true, then the API uses the development
|
||||||
|
// API, instead of the production API.
|
||||||
|
func NewNameAPI(username, token string, dev bool) API {
|
||||||
|
a := API{username: username, token: token}
|
||||||
|
|
||||||
if c.Debug {
|
if dev {
|
||||||
a.baseUrl = devUrl
|
a.baseUrl = devUrl
|
||||||
} else {
|
} else {
|
||||||
a.baseUrl = productionUrl
|
a.baseUrl = productionUrl
|
||||||
|
@ -46,6 +50,11 @@ func NewAPI(c Config) API {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constructs a new Name.com API from a configuration
|
||||||
|
func NewAPIFromConfig(c Config) API {
|
||||||
|
return NewNameAPI(c.Username, c.Token, c.Dev)
|
||||||
|
}
|
||||||
|
|
||||||
func (api API) performRequest(method, url string, body io.Reader) (response []byte, err error) {
|
func (api API) performRequest(method, url string, body io.Reader) (response []byte, err error) {
|
||||||
var client http.Client
|
var client http.Client
|
||||||
req, err := http.NewRequest(method, url, body)
|
req, err := http.NewRequest(method, url, body)
|
||||||
|
@ -65,6 +74,7 @@ func (api API) performRequest(method, url string, body io.Reader) (response []by
|
||||||
return ioutil.ReadAll(resp.Body)
|
return ioutil.ReadAll(resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a slice of DNS records associated with a given hostname.
|
||||||
func (api API) GetRecords(hostname string) (records []DNSRecord, err error) {
|
func (api API) GetRecords(hostname string) (records []DNSRecord, err error) {
|
||||||
resp, err := api.performRequest("GET", fmt.Sprintf("%s%s%s", api.baseUrl, "api/dns/list/", hostname), nil)
|
resp, err := api.performRequest("GET", fmt.Sprintf("%s%s%s", api.baseUrl, "api/dns/list/", hostname), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Debug bool `json:"debug"`
|
Dev bool `json:"dev"`
|
||||||
Domains []string `json:"domains"`
|
Domains []string `json:"domains"`
|
||||||
Interval int `json:"interval"`
|
Interval int `json:"interval"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
|
|
@ -10,10 +10,10 @@ var expectedConfigs []Config
|
||||||
func init() {
|
func init() {
|
||||||
expectedConfigs = []Config{
|
expectedConfigs = []Config{
|
||||||
Config{
|
Config{
|
||||||
Username: "debug-account",
|
Username: "dev-account",
|
||||||
Token: "asdasdasdasdasdad",
|
Token: "asdasdasdasdasdad",
|
||||||
Interval: 60,
|
Interval: 60,
|
||||||
Debug: true,
|
Dev: true,
|
||||||
Domains: []string{"test.com", "fake.com"},
|
Domains: []string{"test.com", "fake.com"},
|
||||||
},
|
},
|
||||||
Config{
|
Config{
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"configs": [
|
"configs": [
|
||||||
{
|
{
|
||||||
"username": "debug-account",
|
"username": "dev-account",
|
||||||
"token": "asdasdasdasdasdad",
|
"token": "asdasdasdasdasdad",
|
||||||
"interval": 60,
|
"interval": 60,
|
||||||
"debug": true,
|
"dev": true,
|
||||||
"domains": [ "test.com", "fake.com" ]
|
"domains": [ "test.com", "fake.com" ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue