mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
migrate code for github
This commit is contained in:
21
vendor/github.com/billputer/go-namecheap/LICENSE
generated
vendored
Normal file
21
vendor/github.com/billputer/go-namecheap/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Bill Wiens
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
43
vendor/github.com/billputer/go-namecheap/README.md
generated
vendored
Normal file
43
vendor/github.com/billputer/go-namecheap/README.md
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
# go-namecheap
|
||||
|
||||
A Go library for using [the Namecheap API](https://www.namecheap.com/support/api/intro.aspx).
|
||||
|
||||
**Build Status:** [](https://travis-ci.org/billputer/go-namecheap)
|
||||
|
||||
## Examples
|
||||
|
||||
```go
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
namecheap "github.com/billputer/go-namecheap"
|
||||
)
|
||||
|
||||
func main() {
|
||||
apiUser := "billwiens"
|
||||
apiToken := "xxxxxxx"
|
||||
userName := "billwiens"
|
||||
|
||||
client := namecheap.NewClient(apiUser, apiToken, userName)
|
||||
|
||||
// Get a list of your domains
|
||||
domains, _ := client.DomainsGetList()
|
||||
for _, domain := range domains {
|
||||
fmt.Printf("Domain: %+v\n\n", domain.Name)
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
For more complete documentation, load up godoc and find the package.
|
||||
|
||||
## Development
|
||||
|
||||
- Source hosted at [GitHub](https://github.com/billputer/go-namecheap)
|
||||
- Report issues and feature requests to [GitHub Issues](https://github.com/billputer/go-namecheap/issues)
|
||||
|
||||
Pull requests welcome!
|
||||
|
||||
## Attribution
|
||||
|
||||
Most concepts and code borrowed from the excellent [go-dnsimple](http://github.com/rubyist/go-dnsimple).
|
98
vendor/github.com/billputer/go-namecheap/dns.go
generated
vendored
Normal file
98
vendor/github.com/billputer/go-namecheap/dns.go
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
package namecheap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
domainsDNSGetHosts = "namecheap.domains.dns.getHosts"
|
||||
domainsDNSSetHosts = "namecheap.domains.dns.setHosts"
|
||||
domainsDNSSetCustom = "namecheap.domains.dns.setCustom"
|
||||
)
|
||||
|
||||
type DomainDNSGetHostsResult struct {
|
||||
Domain string `xml:"Domain,attr"`
|
||||
IsUsingOurDNS bool `xml:"IsUsingOurDNS,attr"`
|
||||
Hosts []DomainDNSHost `xml:"host"`
|
||||
}
|
||||
|
||||
type DomainDNSHost struct {
|
||||
ID int `xml:"HostId,attr"`
|
||||
Name string `xml:"Name,attr"`
|
||||
Type string `xml:"Type,attr"`
|
||||
Address string `xml:"Address,attr"`
|
||||
MXPref int `xml:"MXPref,attr"`
|
||||
TTL int `xml:"TTL,attr"`
|
||||
}
|
||||
|
||||
type DomainDNSSetHostsResult struct {
|
||||
Domain string `xml:"Domain,attr"`
|
||||
IsSuccess bool `xml:"IsSuccess,attr"`
|
||||
}
|
||||
|
||||
func (client *Client) DomainsDNSGetHosts(sld, tld string) (*DomainDNSGetHostsResult, error) {
|
||||
requestInfo := &ApiRequest{
|
||||
command: domainsDNSGetHosts,
|
||||
method: "GET",
|
||||
params: url.Values{},
|
||||
}
|
||||
requestInfo.params.Set("SLD", sld)
|
||||
requestInfo.params.Set("TLD", tld)
|
||||
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.DomainDNSHosts, nil
|
||||
}
|
||||
|
||||
func (client *Client) DomainDNSSetHosts(
|
||||
sld, tld string, hosts []DomainDNSHost,
|
||||
) (*DomainDNSSetHostsResult, error) {
|
||||
requestInfo := &ApiRequest{
|
||||
command: domainsDNSSetHosts,
|
||||
method: "GET",
|
||||
params: url.Values{},
|
||||
}
|
||||
requestInfo.params.Set("SLD", sld)
|
||||
requestInfo.params.Set("TLD", tld)
|
||||
|
||||
for i := range hosts {
|
||||
requestInfo.params.Set(fmt.Sprintf("HostName%v", i+1), hosts[i].Name)
|
||||
requestInfo.params.Set(fmt.Sprintf("RecordType%v", i+1), hosts[i].Type)
|
||||
requestInfo.params.Set(fmt.Sprintf("Address%v", i+1), hosts[i].Address)
|
||||
requestInfo.params.Set(fmt.Sprintf("TTL%v", i+1), strconv.Itoa(hosts[i].TTL))
|
||||
|
||||
}
|
||||
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.DomainDNSSetHosts, nil
|
||||
}
|
||||
|
||||
type DomainDNSSetCustomResult struct {
|
||||
Domain string `xml:"Domain,attr"`
|
||||
Update bool `xml:"Update,attr"`
|
||||
}
|
||||
|
||||
func (client *Client) DomainDNSSetCustom(sld, tld, nameservers string) (*DomainDNSSetCustomResult, error) {
|
||||
requestInfo := &ApiRequest{
|
||||
command: domainsDNSSetCustom,
|
||||
method: "GET",
|
||||
params: url.Values{},
|
||||
}
|
||||
requestInfo.params.Set("SLD", sld)
|
||||
requestInfo.params.Set("TLD", tld)
|
||||
requestInfo.params.Set("Nameservers", nameservers)
|
||||
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.DomainDNSSetCustom, nil
|
||||
}
|
136
vendor/github.com/billputer/go-namecheap/domain.go
generated
vendored
Normal file
136
vendor/github.com/billputer/go-namecheap/domain.go
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
package namecheap
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
domainsGetList = "namecheap.domains.getList"
|
||||
domainsGetInfo = "namecheap.domains.getInfo"
|
||||
domainsCheck = "namecheap.domains.check"
|
||||
domainsCreate = "namecheap.domains.create"
|
||||
)
|
||||
|
||||
// DomainGetListResult represents the data returned by 'domains.getList'
|
||||
type DomainGetListResult struct {
|
||||
ID int `xml:"ID,attr"`
|
||||
Name string `xml:"Name,attr"`
|
||||
User string `xml:"User,attr"`
|
||||
Created string `xml:"Created,attr"`
|
||||
Expires string `xml:"Expires,attr"`
|
||||
IsExpired bool `xml:"IsExpired,attr"`
|
||||
IsLocked bool `xml:"IsLocked,attr"`
|
||||
AutoRenew bool `xml:"AutoRenew,attr"`
|
||||
WhoisGuard string `xml:"WhoisGuard,attr"`
|
||||
}
|
||||
|
||||
// DomainInfo represents the data returned by 'domains.getInfo'
|
||||
type DomainInfo struct {
|
||||
ID int `xml:"ID,attr"`
|
||||
Name string `xml:"DomainName,attr"`
|
||||
Owner string `xml:"OwnerName,attr"`
|
||||
Created string `xml:"DomainDetails>CreatedDate"`
|
||||
Expires string `xml:"DomainDetails>ExpiredDate"`
|
||||
IsExpired bool `xml:"IsExpired,attr"`
|
||||
IsLocked bool `xml:"IsLocked,attr"`
|
||||
AutoRenew bool `xml:"AutoRenew,attr"`
|
||||
DNSDetails DNSDetails `xml:"DnsDetails"`
|
||||
}
|
||||
|
||||
type DNSDetails struct {
|
||||
ProviderType string `xml:"ProviderType,attr"`
|
||||
IsUsingOurDNS bool `xml:"IsUsingOurDNS,attr"`
|
||||
Nameservers []string `xml:"Nameserver"`
|
||||
}
|
||||
|
||||
type DomainCheckResult struct {
|
||||
Domain string `xml:"Domain,attr"`
|
||||
Available bool `xml:"Available,attr"`
|
||||
}
|
||||
|
||||
type DomainCreateResult struct {
|
||||
Domain string `xml:"Domain,attr"`
|
||||
Registered bool `xml:"Registered,attr"`
|
||||
ChargedAmount float64 `xml:"ChargedAmount,attr"`
|
||||
DomainID int `xml:"DomainID,attr"`
|
||||
OrderID int `xml:"OrderID,attr"`
|
||||
TransactionID int `xml:"TransactionID,attr"`
|
||||
WhoisGuardEnable bool `xml:"WhoisGuardEnable,attr"`
|
||||
NonRealTimeDomain bool `xml:"NonRealTimeDomain,attr"`
|
||||
}
|
||||
|
||||
func (client *Client) DomainsGetList() ([]DomainGetListResult, error) {
|
||||
requestInfo := &ApiRequest{
|
||||
command: domainsGetList,
|
||||
method: "GET",
|
||||
params: url.Values{},
|
||||
}
|
||||
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.Domains, nil
|
||||
}
|
||||
|
||||
func (client *Client) DomainGetInfo(domainName string) (*DomainInfo, error) {
|
||||
requestInfo := &ApiRequest{
|
||||
command: domainsGetInfo,
|
||||
method: "GET",
|
||||
params: url.Values{},
|
||||
}
|
||||
|
||||
requestInfo.params.Set("DomainName", domainName)
|
||||
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.DomainInfo, nil
|
||||
}
|
||||
|
||||
func (client *Client) DomainsCheck(domainNames ...string) ([]DomainCheckResult, error) {
|
||||
requestInfo := &ApiRequest{
|
||||
command: domainsCheck,
|
||||
method: "GET",
|
||||
params: url.Values{},
|
||||
}
|
||||
|
||||
requestInfo.params.Set("DomainList", strings.Join(domainNames, ","))
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.DomainsCheck, nil
|
||||
}
|
||||
|
||||
func (client *Client) DomainCreate(domainName string, years int) (*DomainCreateResult, error) {
|
||||
if client.Registrant == nil {
|
||||
return nil, errors.New("Registrant information on client cannot be empty")
|
||||
}
|
||||
|
||||
requestInfo := &ApiRequest{
|
||||
command: domainsCreate,
|
||||
method: "POST",
|
||||
params: url.Values{},
|
||||
}
|
||||
|
||||
requestInfo.params.Set("DomainName", domainName)
|
||||
requestInfo.params.Set("Years", strconv.Itoa(years))
|
||||
if err := client.Registrant.addValues(requestInfo.params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.DomainCreate, nil
|
||||
}
|
161
vendor/github.com/billputer/go-namecheap/namecheap.go
generated
vendored
Normal file
161
vendor/github.com/billputer/go-namecheap/namecheap.go
generated
vendored
Normal file
@ -0,0 +1,161 @@
|
||||
// Package namecheap implements a client for the Namecheap API.
|
||||
//
|
||||
// In order to use this package you will need a Namecheap account and your API Token.
|
||||
package namecheap
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const defaultBaseURL = "https://api.namecheap.com/xml.response"
|
||||
|
||||
// Client represents a client used to make calls to the Namecheap API.
|
||||
type Client struct {
|
||||
ApiUser string
|
||||
ApiToken string
|
||||
UserName string
|
||||
HttpClient *http.Client
|
||||
|
||||
// Base URL for API requests.
|
||||
// Defaults to the public Namecheap API,
|
||||
// but can be set to a different endpoint (e.g. the sandbox).
|
||||
// BaseURL should always be specified with a trailing slash.
|
||||
BaseURL string
|
||||
|
||||
*Registrant
|
||||
}
|
||||
|
||||
type ApiRequest struct {
|
||||
method string
|
||||
command string
|
||||
params url.Values
|
||||
}
|
||||
|
||||
type ApiResponse struct {
|
||||
Status string `xml:"Status,attr"`
|
||||
Command string `xml:"RequestedCommand"`
|
||||
Domains []DomainGetListResult `xml:"CommandResponse>DomainGetListResult>Domain"`
|
||||
DomainInfo *DomainInfo `xml:"CommandResponse>DomainGetInfoResult"`
|
||||
DomainDNSHosts *DomainDNSGetHostsResult `xml:"CommandResponse>DomainDNSGetHostsResult"`
|
||||
DomainDNSSetHosts *DomainDNSSetHostsResult `xml:"CommandResponse>DomainDNSSetHostsResult"`
|
||||
DomainCreate *DomainCreateResult `xml:"CommandResponse>DomainCreateResult"`
|
||||
DomainsCheck []DomainCheckResult `xml:"CommandResponse>DomainCheckResult"`
|
||||
DomainNSInfo *DomainNSInfoResult `xml:"CommandResponse>DomainNSInfoResult"`
|
||||
DomainDNSSetCustom *DomainDNSSetCustomResult `xml:"CommandResponse>DomainDNSSetCustomResult"`
|
||||
Errors []ApiError `xml:"Errors>Error"`
|
||||
}
|
||||
|
||||
// ApiError is the format of the error returned in the api responses.
|
||||
type ApiError struct {
|
||||
Number int `xml:"Number,attr"`
|
||||
Message string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
func (err *ApiError) Error() string {
|
||||
return err.Message
|
||||
}
|
||||
|
||||
func NewClient(apiUser, apiToken, userName string) *Client {
|
||||
return &Client{
|
||||
ApiUser: apiUser,
|
||||
ApiToken: apiToken,
|
||||
UserName: userName,
|
||||
HttpClient: http.DefaultClient,
|
||||
BaseURL: defaultBaseURL,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRegistrant associates a new registrant with the
|
||||
func (client *Client) NewRegistrant(
|
||||
firstName, lastName,
|
||||
addr1, addr2,
|
||||
city, state, postalCode, country,
|
||||
phone, email string,
|
||||
) {
|
||||
client.Registrant = newRegistrant(
|
||||
firstName, lastName,
|
||||
addr1, addr2,
|
||||
city, state, postalCode, country,
|
||||
phone, email,
|
||||
)
|
||||
}
|
||||
|
||||
func (client *Client) do(request *ApiRequest) (*ApiResponse, error) {
|
||||
if request.method == "" {
|
||||
return nil, errors.New("request method cannot be blank")
|
||||
}
|
||||
|
||||
body, _, err := client.sendRequest(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := new(ApiResponse)
|
||||
if err = xml.Unmarshal(body, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Status == "ERROR" {
|
||||
errMsg := ""
|
||||
for _, apiError := range resp.Errors {
|
||||
errMsg += fmt.Sprintf("Error %d: %s\n", apiError.Number, apiError.Message)
|
||||
}
|
||||
return nil, errors.New(errMsg)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *Client) makeRequest(request *ApiRequest) (*http.Request, error) {
|
||||
url, err := url.Parse(client.BaseURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := request.params
|
||||
p.Set("ApiUser", client.ApiUser)
|
||||
p.Set("ApiKey", client.ApiToken)
|
||||
p.Set("UserName", client.UserName)
|
||||
// This param is required by the API, but not actually used.
|
||||
p.Set("ClientIp", "127.0.0.1")
|
||||
p.Set("Command", request.command)
|
||||
url.RawQuery = p.Encode()
|
||||
|
||||
// UGH
|
||||
//
|
||||
// Need this for the domain name part of the domains.check endpoint
|
||||
url.RawQuery = strings.Replace(url.RawQuery, "%2C", ",", -1)
|
||||
|
||||
urlString := fmt.Sprintf("%s?%s", client.BaseURL, url.RawQuery)
|
||||
req, err := http.NewRequest(request.method, urlString, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (client *Client) sendRequest(request *ApiRequest) ([]byte, int, error) {
|
||||
req, err := client.makeRequest(request)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
resp, err := client.HttpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return buf, resp.StatusCode, nil
|
||||
}
|
35
vendor/github.com/billputer/go-namecheap/ns.go
generated
vendored
Normal file
35
vendor/github.com/billputer/go-namecheap/ns.go
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
package namecheap
|
||||
|
||||
import "net/url"
|
||||
|
||||
const (
|
||||
nsCreate = "namecheap.domains.ns.create"
|
||||
nsDelete = "namecheap.domains.ns.delete"
|
||||
nsGetInfo = "namecheap.domains.ns.getInfo"
|
||||
nsUpdate = "namecheap.domains.ns.update"
|
||||
)
|
||||
|
||||
type DomainNSInfoResult struct {
|
||||
Domain string `xml:"Domain,attr"`
|
||||
Nameserver string `xml:"Nameserver,attr"`
|
||||
IP string `xml:"IP,attr"`
|
||||
Statuses []string `xml:"NameserverStatuses>Status"`
|
||||
}
|
||||
|
||||
func (client *Client) NSGetInfo(sld, tld, nameserver string) (*DomainNSInfoResult, error) {
|
||||
requestInfo := &ApiRequest{
|
||||
command: nsGetInfo,
|
||||
method: "GET",
|
||||
params: url.Values{},
|
||||
}
|
||||
requestInfo.params.Set("SLD", sld)
|
||||
requestInfo.params.Set("TLD", tld)
|
||||
requestInfo.params.Set("Nameserver", nameserver)
|
||||
|
||||
resp, err := client.do(requestInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.DomainNSInfo, nil
|
||||
}
|
119
vendor/github.com/billputer/go-namecheap/registrant.go
generated
vendored
Normal file
119
vendor/github.com/billputer/go-namecheap/registrant.go
generated
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
package namecheap
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Registrant is a struct that contains all the data necesary to register a domain.
|
||||
// That is to say, every field in this struct is REQUIRED by the namecheap api to
|
||||
// crate a new domain.
|
||||
// In order for `addValues` method to work, all fields must remain strings.
|
||||
type Registrant struct {
|
||||
RegistrantFirstName, RegistrantLastName,
|
||||
RegistrantAddress1, RegistrantAddress2, RegistrantCity,
|
||||
RegistrantStateProvince, RegistrantPostalCode, RegistrantCountry,
|
||||
RegistrantPhone, RegistrantEmailAddress,
|
||||
|
||||
TechFirstName, TechLastName,
|
||||
TechAddress1, TechAddress2,
|
||||
TechCity, TechStateProvince, TechPostalCode, TechCountry,
|
||||
TechPhone, TechEmailAddress,
|
||||
|
||||
AdminFirstName, AdminLastName,
|
||||
AdminAddress1, AdminAddress2,
|
||||
AdminCity, AdminStateProvince, AdminPostalCode, AdminCountry,
|
||||
AdminPhone, AdminEmailAddress,
|
||||
|
||||
AuxBillingFirstName, AuxBillingLastName,
|
||||
AuxBillingAddress1, AuxBillingAddress2,
|
||||
AuxBillingCity, AuxBillingStateProvince, AuxBillingPostalCode, AuxBillingCountry,
|
||||
AuxBillingPhone, AuxBillingEmailAddress string
|
||||
}
|
||||
|
||||
// newRegistrant return a new registrant where all the required fields are the same.
|
||||
// Feel free to change them as needed
|
||||
func newRegistrant(
|
||||
firstName, lastName,
|
||||
addr1, addr2,
|
||||
city, state, postalCode, country,
|
||||
phone, email string,
|
||||
) *Registrant {
|
||||
return &Registrant{
|
||||
RegistrantFirstName: firstName,
|
||||
RegistrantLastName: lastName,
|
||||
RegistrantAddress1: addr1,
|
||||
RegistrantAddress2: addr2,
|
||||
RegistrantCity: city,
|
||||
RegistrantStateProvince: state,
|
||||
RegistrantPostalCode: postalCode,
|
||||
RegistrantCountry: country,
|
||||
RegistrantPhone: phone,
|
||||
RegistrantEmailAddress: email,
|
||||
TechFirstName: firstName,
|
||||
TechLastName: lastName,
|
||||
TechAddress1: addr1,
|
||||
TechAddress2: addr2,
|
||||
TechCity: city,
|
||||
TechStateProvince: state,
|
||||
TechPostalCode: postalCode,
|
||||
TechCountry: country,
|
||||
TechPhone: phone,
|
||||
TechEmailAddress: email,
|
||||
AdminFirstName: firstName,
|
||||
AdminLastName: lastName,
|
||||
AdminAddress1: addr1,
|
||||
AdminAddress2: addr2,
|
||||
AdminCity: city,
|
||||
AdminStateProvince: state,
|
||||
AdminPostalCode: postalCode,
|
||||
AdminCountry: country,
|
||||
AdminPhone: phone,
|
||||
AdminEmailAddress: email,
|
||||
AuxBillingFirstName: firstName,
|
||||
AuxBillingLastName: lastName,
|
||||
AuxBillingAddress1: addr1,
|
||||
AuxBillingAddress2: addr2,
|
||||
AuxBillingCity: city,
|
||||
AuxBillingStateProvince: state,
|
||||
AuxBillingPostalCode: postalCode,
|
||||
AuxBillingCountry: country,
|
||||
AuxBillingPhone: phone,
|
||||
AuxBillingEmailAddress: email,
|
||||
}
|
||||
}
|
||||
|
||||
// addValues adds the fields of this struct to the passed in url.Values.
|
||||
// It is important that all the fields of Registrant remain string type.
|
||||
func (reg *Registrant) addValues(u url.Values) error {
|
||||
if u == nil {
|
||||
return errors.New("nil value passed as url.Values")
|
||||
}
|
||||
|
||||
val := reflect.ValueOf(*reg)
|
||||
t := val.Type()
|
||||
for i := 0; i < val.NumField(); i++ {
|
||||
fieldName := t.Field(i).Name
|
||||
field := val.Field(i).String()
|
||||
if ty := val.Field(i).Kind(); ty != reflect.String {
|
||||
return fmt.Errorf(
|
||||
"Registrant cannot have types that aren't string; %s is type %s",
|
||||
fieldName, ty,
|
||||
)
|
||||
}
|
||||
if field == "" {
|
||||
if strings.Contains(fieldName, "ddress2") {
|
||||
continue
|
||||
}
|
||||
|
||||
return fmt.Errorf("Field %s cannot be empty", fieldName)
|
||||
}
|
||||
|
||||
u.Set(fieldName, fmt.Sprintf("%v", field))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user