-
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.
Signed-off-by: Jasmin Gacic <jasmin.gacic@gmail.com>
- Loading branch information
1 parent
cdef4ba
commit fd94b4f
Showing
10 changed files
with
219 additions
and
117 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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Kusk Gateway API | ||
* | ||
* This is the Kusk Gateway Management API | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package openapi | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// NamespacesApiController binds http requests to an api service and writes the service results to the http response | ||
type NamespacesApiController struct { | ||
service NamespacesApiServicer | ||
errorHandler ErrorHandler | ||
} | ||
|
||
// NamespacesApiOption for how the controller is set up. | ||
type NamespacesApiOption func(*NamespacesApiController) | ||
|
||
// WithNamespacesApiErrorHandler inject ErrorHandler into controller | ||
func WithNamespacesApiErrorHandler(h ErrorHandler) NamespacesApiOption { | ||
return func(c *NamespacesApiController) { | ||
c.errorHandler = h | ||
} | ||
} | ||
|
||
// NewNamespacesApiController creates a default api controller | ||
func NewNamespacesApiController(s NamespacesApiServicer, opts ...NamespacesApiOption) Router { | ||
controller := &NamespacesApiController{ | ||
service: s, | ||
errorHandler: DefaultErrorHandler, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(controller) | ||
} | ||
|
||
return controller | ||
} | ||
|
||
// Routes returns all of the api route for the NamespacesApiController | ||
func (c *NamespacesApiController) Routes() Routes { | ||
return Routes{ | ||
{ | ||
"GetNamespaces", | ||
strings.ToUpper("Get"), | ||
"/namespaces", | ||
c.GetNamespaces, | ||
}, | ||
} | ||
} | ||
|
||
// GetNamespaces - Get a list of namespaces | ||
func (c *NamespacesApiController) GetNamespaces(w http.ResponseWriter, r *http.Request) { | ||
result, err := c.service.GetNamespaces(r.Context()) | ||
// If an error occurred, encode the error with the status code | ||
if err != nil { | ||
c.errorHandler(w, r, err, &result) | ||
return | ||
} | ||
// If no error, encode the body and the result code | ||
EncodeJSONResponse(result.Body, &result.Code, w) | ||
|
||
} |
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,42 @@ | ||
/* | ||
* Kusk Gateway API | ||
* | ||
* This is the Kusk Gateway Management API | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package openapi | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
kusk "github.com/GIT_USER_ID/GIT_REPO_ID/kusk" | ||
) | ||
|
||
// NamespacesApiService is a service that implements the logic for the NamespacesApiServicer | ||
// This service should implement the business logic for every endpoint for the NamespacesApi API. | ||
// Include any external packages or services that will be required by this service. | ||
type NamespacesApiService struct { | ||
kuskClient kusk.Client | ||
} | ||
|
||
// NewNamespacesApiService creates a default api service | ||
func NewNamespacesApiService(kuskClient kusk.Client) NamespacesApiServicer { | ||
return &NamespacesApiService{kuskClient: kuskClient} | ||
} | ||
|
||
// GetNamespaces - Get a list of namespaces | ||
func (s *NamespacesApiService) GetNamespaces(ctx context.Context) (ImplResponse, error) { | ||
namespaces, err := s.kuskClient.ListNamespaces() | ||
if err != nil { | ||
return Response(http.StatusInternalServerError, err), err | ||
} | ||
toReturn := []NamespaceItem{} | ||
for _, ns := range namespaces.Items { | ||
toReturn = append(toReturn, NamespaceItem{ns.Name}) | ||
} | ||
return Response(http.StatusOK, toReturn), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Kusk Gateway API | ||
* | ||
* This is the Kusk Gateway Management API | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package openapi | ||
|
||
type NamespaceItem struct { | ||
Name string `json:"name,omitempty"` | ||
} | ||
|
||
// AssertNamespaceItemRequired checks if the required fields are not zero-ed | ||
func AssertNamespaceItemRequired(obj NamespaceItem) error { | ||
return nil | ||
} | ||
|
||
// AssertRecurseNamespaceItemRequired recursively checks if required fields are not zero-ed in a nested slice. | ||
// Accepts only nested slice of NamespaceItem (e.g. [][]NamespaceItem), otherwise ErrTypeAssertionError is thrown. | ||
func AssertRecurseNamespaceItemRequired(objSlice interface{}) error { | ||
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error { | ||
aNamespaceItem, ok := obj.(NamespaceItem) | ||
if !ok { | ||
return ErrTypeAssertionError | ||
} | ||
return AssertNamespaceItemRequired(aNamespaceItem) | ||
}) | ||
} |
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