From f8c8a2fc3ab26ee8b9bd294e317c56fc3ce11c4c Mon Sep 17 00:00:00 2001 From: Dan O'Neill Date: Mon, 20 Nov 2023 19:12:52 -0800 Subject: [PATCH] Refactor api source to api package rename to service --- cmd/api.go => api/earthranger_service.go | 4 ++-- cmd/auth.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) rename cmd/api.go => api/earthranger_service.go (96%) diff --git a/cmd/api.go b/api/earthranger_service.go similarity index 96% rename from cmd/api.go rename to api/earthranger_service.go index 2b965f1..85b5e1e 100644 --- a/cmd/api.go +++ b/api/earthranger_service.go @@ -1,4 +1,4 @@ -package cmd +package api import ( "encoding/json" @@ -32,7 +32,7 @@ type Response struct { // package funtions // ---------------------------------------------- -func authenticate(sitename, username, password string) (*Response, error) { +func Authenticate(sitename, username, password string) (*Response, error) { // Create a new HTTP client and make a POST request to the authentication endpoint client := &http.Client{} req, err := http.NewRequest("POST", fmt.Sprintf("https://%s%s%s", sitename, DOMAIN, API_AUTH), nil) diff --git a/cmd/auth.go b/cmd/auth.go index 180f570..c09352a 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/doneill/er-cli-go/api" "github.com/spf13/cobra" ) @@ -41,7 +42,7 @@ func auth() { } // Call the authenticate function to get the access token and expires in - response, err := authenticate(SITENAME, USERNAME, password) + response, err := api.Authenticate(SITENAME, USERNAME, password) if err != nil { fmt.Println("Error authenticating:", err) os.Exit(1)