-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
207 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
viper.SetConfigName("config") // name of config file (without extension) | ||
viper.AddConfigPath(".") // optionally look for config in the working directory | ||
err := viper.ReadInConfig() // Find and read the config file | ||
|
||
if err != nil { // Handle errors reading the config file | ||
panic(fmt.Errorf("Fatal error config file: %s \n", err)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package godaddy | ||
|
||
import ( | ||
// "github.com/spf13/cobra" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/viper" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
// CheckRequestBody represents the retrieved response from checking if a domain exists | ||
type CheckRequestBody struct { | ||
available bool | ||
definitive bool | ||
domain string | ||
period int | ||
price uint64 | ||
} | ||
|
||
// CheckAvailability checks if a Domain name is available | ||
func CheckAvailability(domain string) (data CheckRequestBody, err error) { | ||
ssoKey := viper.GetString("ssoKey") | ||
apiURL, err := GetApiUrl("v1") | ||
if err != nil { | ||
return data, err | ||
} | ||
client := &http.Client{} | ||
req, err := http.NewRequest("GET", apiURL, nil) | ||
if err != nil { | ||
return data, err | ||
} | ||
req.Header.Add("Authorization", fmt.Sprintf("sso-key: %s", ssoKey)) | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return data, err | ||
} | ||
if resp.StatusCode != 200 { | ||
return data, fmt.Errorf("%s: %s", resp.StatusCode, resp.Status) | ||
} | ||
fmt.Println(resp) | ||
defer resp.Body.Close() | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return data, err | ||
} | ||
err = json.Unmarshal(body, &data) | ||
if err != nil { | ||
return data, err | ||
} | ||
return | ||
} |
Oops, something went wrong.