-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
12 changed files
with
248 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,66 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
|
||
serverType "github.com/cloud-club/Aviator-service/types/server" | ||
) | ||
|
||
type ProductService struct{} | ||
|
||
func NewProductService() ProductInterface { | ||
return &ProductService{} | ||
} | ||
|
||
type ProductInterface interface { | ||
Get(url string, request *serverType.GetProductRequest) (*serverType.ProductList, error) | ||
} | ||
|
||
func (product *ProductService) Get(url string, request *serverType.GetProductRequest) (*serverType.ProductList, error) { | ||
// Set url with query parameters | ||
// However, there is no must required query parameters for this API, so we will comment this line right now. | ||
//requestParams := serverType.CreateRequestString(request) | ||
requestParams := serverType.RequestString(request) | ||
|
||
// Create an HTTP request | ||
req, err := http.NewRequest(http.MethodGet, url+requestParams, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Set HTTP header for NCP authorization | ||
SetNCPHeader(req, "6CmrDJ4KaswJ10g25GEP", "OvZ7QHH0Bi3AwGn5rlsD7xoC986bEOiIjdbwMFCo") | ||
|
||
// Make the HTTP request | ||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Check the response status | ||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("unexpected response status: %s", resp.Status) | ||
} | ||
|
||
// Read the response body | ||
responseByteData, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
return nil, err | ||
} | ||
|
||
// Convert the response body to the struct | ||
var sl *serverType.ProductList | ||
responseInterface, err := serverType.MapResponse(responseByteData, &sl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// interface{} to *serverType.SubnetList | ||
responseStruct := responseInterface.(**serverType.ProductList) | ||
|
||
return *responseStruct, nil | ||
} |
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
File renamed without changes.
Oops, something went wrong.