forked from loafle/openapi-generator-original
sync master, update doc
This commit is contained in:
@@ -1 +1 @@
|
||||
4.2.0-SNAPSHOT
|
||||
5.0.0-SNAPSHOT
|
||||
96
samples/server/petstore/go-api-server/go/api.go
Normal file
96
samples/server/petstore/go-api-server/go/api.go
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* API version: 1.0.0
|
||||
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
||||
*/
|
||||
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
||||
// PetApiRouter defines the required methods for binding the api requests to a responses for the PetApi
|
||||
// The PetApiRouter implementation should parse necessary information from the http request,
|
||||
// pass the data to a PetApiServicer to perform the required actions, then write the service results to the http response.
|
||||
type PetApiRouter interface {
|
||||
AddPet(http.ResponseWriter, *http.Request)
|
||||
DeletePet(http.ResponseWriter, *http.Request)
|
||||
FindPetsByStatus(http.ResponseWriter, *http.Request)
|
||||
FindPetsByTags(http.ResponseWriter, *http.Request)
|
||||
GetPetById(http.ResponseWriter, *http.Request)
|
||||
UpdatePet(http.ResponseWriter, *http.Request)
|
||||
UpdatePetWithForm(http.ResponseWriter, *http.Request)
|
||||
UploadFile(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
// StoreApiRouter defines the required methods for binding the api requests to a responses for the StoreApi
|
||||
// The StoreApiRouter implementation should parse necessary information from the http request,
|
||||
// pass the data to a StoreApiServicer to perform the required actions, then write the service results to the http response.
|
||||
type StoreApiRouter interface {
|
||||
DeleteOrder(http.ResponseWriter, *http.Request)
|
||||
GetInventory(http.ResponseWriter, *http.Request)
|
||||
GetOrderById(http.ResponseWriter, *http.Request)
|
||||
PlaceOrder(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
// UserApiRouter defines the required methods for binding the api requests to a responses for the UserApi
|
||||
// The UserApiRouter implementation should parse necessary information from the http request,
|
||||
// pass the data to a UserApiServicer to perform the required actions, then write the service results to the http response.
|
||||
type UserApiRouter interface {
|
||||
CreateUser(http.ResponseWriter, *http.Request)
|
||||
CreateUsersWithArrayInput(http.ResponseWriter, *http.Request)
|
||||
CreateUsersWithListInput(http.ResponseWriter, *http.Request)
|
||||
DeleteUser(http.ResponseWriter, *http.Request)
|
||||
GetUserByName(http.ResponseWriter, *http.Request)
|
||||
LoginUser(http.ResponseWriter, *http.Request)
|
||||
LogoutUser(http.ResponseWriter, *http.Request)
|
||||
UpdateUser(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
|
||||
// PetApiServicer defines the api actions for the PetApi service
|
||||
// This interface intended to stay up to date with the openapi yaml used to generate it,
|
||||
// while the service implementation can ignored with the .openapi-generator-ignore file
|
||||
// and updated with the logic required for the API.
|
||||
type PetApiServicer interface {
|
||||
AddPet(Pet) (interface{}, error)
|
||||
DeletePet(int64, string) (interface{}, error)
|
||||
FindPetsByStatus([]string) (interface{}, error)
|
||||
FindPetsByTags([]string) (interface{}, error)
|
||||
GetPetById(int64) (interface{}, error)
|
||||
UpdatePet(Pet) (interface{}, error)
|
||||
UpdatePetWithForm(int64, string, string) (interface{}, error)
|
||||
UploadFile(int64, string, *os.File) (interface{}, error)
|
||||
}
|
||||
|
||||
|
||||
// StoreApiServicer defines the api actions for the StoreApi service
|
||||
// This interface intended to stay up to date with the openapi yaml used to generate it,
|
||||
// while the service implementation can ignored with the .openapi-generator-ignore file
|
||||
// and updated with the logic required for the API.
|
||||
type StoreApiServicer interface {
|
||||
DeleteOrder(string) (interface{}, error)
|
||||
GetInventory() (interface{}, error)
|
||||
GetOrderById(int64) (interface{}, error)
|
||||
PlaceOrder(Order) (interface{}, error)
|
||||
}
|
||||
|
||||
|
||||
// UserApiServicer defines the api actions for the UserApi service
|
||||
// This interface intended to stay up to date with the openapi yaml used to generate it,
|
||||
// while the service implementation can ignored with the .openapi-generator-ignore file
|
||||
// and updated with the logic required for the API.
|
||||
type UserApiServicer interface {
|
||||
CreateUser(User) (interface{}, error)
|
||||
CreateUsersWithArrayInput([]User) (interface{}, error)
|
||||
CreateUsersWithListInput([]User) (interface{}, error)
|
||||
DeleteUser(string) (interface{}, error)
|
||||
GetUserByName(string) (interface{}, error)
|
||||
LoginUser(string, string) (interface{}, error)
|
||||
LogoutUser() (interface{}, error)
|
||||
UpdateUser(string, User) (interface{}, error)
|
||||
}
|
||||
@@ -10,53 +10,227 @@
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// A PetApiController binds http requests to an api service and writes the service results to the http response
|
||||
type PetApiController struct {
|
||||
service PetApiServicer
|
||||
}
|
||||
|
||||
// NewPetApiController creates a default api controller
|
||||
func NewPetApiController(s PetApiServicer) Router {
|
||||
return &PetApiController{ service: s }
|
||||
}
|
||||
|
||||
// Routes returns all of the api route for the PetApiController
|
||||
func (c *PetApiController) Routes() Routes {
|
||||
return Routes{
|
||||
{
|
||||
"AddPet",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/pet",
|
||||
c.AddPet,
|
||||
},
|
||||
{
|
||||
"DeletePet",
|
||||
strings.ToUpper("Delete"),
|
||||
"/v2/pet/{petId}",
|
||||
c.DeletePet,
|
||||
},
|
||||
{
|
||||
"FindPetsByStatus",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/pet/findByStatus",
|
||||
c.FindPetsByStatus,
|
||||
},
|
||||
{
|
||||
"FindPetsByTags",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/pet/findByTags",
|
||||
c.FindPetsByTags,
|
||||
},
|
||||
{
|
||||
"GetPetById",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/pet/{petId}",
|
||||
c.GetPetById,
|
||||
},
|
||||
{
|
||||
"UpdatePet",
|
||||
strings.ToUpper("Put"),
|
||||
"/v2/pet",
|
||||
c.UpdatePet,
|
||||
},
|
||||
{
|
||||
"UpdatePetWithForm",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/pet/{petId}",
|
||||
c.UpdatePetWithForm,
|
||||
},
|
||||
{
|
||||
"UploadFile",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/pet/{petId}/uploadImage",
|
||||
c.UploadFile,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// AddPet - Add a new pet to the store
|
||||
func AddPet(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) AddPet(w http.ResponseWriter, r *http.Request) {
|
||||
body := &Pet{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.AddPet(*body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// DeletePet - Deletes a pet
|
||||
func DeletePet(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) DeletePet(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
apiKey := r.Header.Get("apiKey")
|
||||
result, err := c.service.DeletePet(petId, apiKey)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// FindPetsByStatus - Finds Pets by status
|
||||
func FindPetsByStatus(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) FindPetsByStatus(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
status := strings.Split(query.Get("status"), ",")
|
||||
result, err := c.service.FindPetsByStatus(status)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// FindPetsByTags - Finds Pets by tags
|
||||
func FindPetsByTags(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) FindPetsByTags(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
tags := strings.Split(query.Get("tags"), ",")
|
||||
result, err := c.service.FindPetsByTags(tags)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// GetPetById - Find pet by ID
|
||||
func GetPetById(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) GetPetById(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.GetPetById(petId)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// UpdatePet - Update an existing pet
|
||||
func UpdatePet(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) UpdatePet(w http.ResponseWriter, r *http.Request) {
|
||||
body := &Pet{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.UpdatePet(*body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// UpdatePetWithForm - Updates a pet in the store with form data
|
||||
func UpdatePetWithForm(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) UpdatePetWithForm(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
name := r.FormValue("name")
|
||||
status := r.FormValue("status")
|
||||
result, err := c.service.UpdatePetWithForm(petId, name, status)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// UploadFile - uploads an image
|
||||
func UploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *PetApiController) UploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
additionalMetadata := r.FormValue("additionalMetadata")
|
||||
file, err := ReadFormFileToTempFile(r, "file")
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.UploadFile(petId, additionalMetadata, file)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
82
samples/server/petstore/go-api-server/go/api_pet_service.go
Normal file
82
samples/server/petstore/go-api-server/go/api_pet_service.go
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* API version: 1.0.0
|
||||
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
||||
*/
|
||||
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
// PetApiService is a service that implents the logic for the PetApiServicer
|
||||
// This service should implement the business logic for every endpoint for the PetApi API.
|
||||
// Include any external packages or services that will be required by this service.
|
||||
type PetApiService struct {
|
||||
}
|
||||
|
||||
// NewPetApiService creates a default api service
|
||||
func NewPetApiService() PetApiServicer {
|
||||
return &PetApiService{}
|
||||
}
|
||||
|
||||
// AddPet - Add a new pet to the store
|
||||
func (s *PetApiService) AddPet(body Pet) (interface{}, error) {
|
||||
// TODO - update AddPet with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'AddPet' not implemented")
|
||||
}
|
||||
|
||||
// DeletePet - Deletes a pet
|
||||
func (s *PetApiService) DeletePet(petId int64, apiKey string) (interface{}, error) {
|
||||
// TODO - update DeletePet with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'DeletePet' not implemented")
|
||||
}
|
||||
|
||||
// FindPetsByStatus - Finds Pets by status
|
||||
func (s *PetApiService) FindPetsByStatus(status []string) (interface{}, error) {
|
||||
// TODO - update FindPetsByStatus with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'FindPetsByStatus' not implemented")
|
||||
}
|
||||
|
||||
// FindPetsByTags - Finds Pets by tags
|
||||
func (s *PetApiService) FindPetsByTags(tags []string) (interface{}, error) {
|
||||
// TODO - update FindPetsByTags with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'FindPetsByTags' not implemented")
|
||||
}
|
||||
|
||||
// GetPetById - Find pet by ID
|
||||
func (s *PetApiService) GetPetById(petId int64) (interface{}, error) {
|
||||
// TODO - update GetPetById with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'GetPetById' not implemented")
|
||||
}
|
||||
|
||||
// UpdatePet - Update an existing pet
|
||||
func (s *PetApiService) UpdatePet(body Pet) (interface{}, error) {
|
||||
// TODO - update UpdatePet with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'UpdatePet' not implemented")
|
||||
}
|
||||
|
||||
// UpdatePetWithForm - Updates a pet in the store with form data
|
||||
func (s *PetApiService) UpdatePetWithForm(petId int64, name string, status string) (interface{}, error) {
|
||||
// TODO - update UpdatePetWithForm with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'UpdatePetWithForm' not implemented")
|
||||
}
|
||||
|
||||
// UploadFile - uploads an image
|
||||
func (s *PetApiService) UploadFile(petId int64, additionalMetadata string, file *os.File) (interface{}, error) {
|
||||
// TODO - update UploadFile with the required logic for this service method.
|
||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'UploadFile' not implemented")
|
||||
}
|
||||
@@ -10,29 +10,108 @@
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// A StoreApiController binds http requests to an api service and writes the service results to the http response
|
||||
type StoreApiController struct {
|
||||
service StoreApiServicer
|
||||
}
|
||||
|
||||
// NewStoreApiController creates a default api controller
|
||||
func NewStoreApiController(s StoreApiServicer) Router {
|
||||
return &StoreApiController{ service: s }
|
||||
}
|
||||
|
||||
// Routes returns all of the api route for the StoreApiController
|
||||
func (c *StoreApiController) Routes() Routes {
|
||||
return Routes{
|
||||
{
|
||||
"DeleteOrder",
|
||||
strings.ToUpper("Delete"),
|
||||
"/v2/store/order/{orderId}",
|
||||
c.DeleteOrder,
|
||||
},
|
||||
{
|
||||
"GetInventory",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/store/inventory",
|
||||
c.GetInventory,
|
||||
},
|
||||
{
|
||||
"GetOrderById",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/store/order/{orderId}",
|
||||
c.GetOrderById,
|
||||
},
|
||||
{
|
||||
"PlaceOrder",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/store/order",
|
||||
c.PlaceOrder,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteOrder - Delete purchase order by ID
|
||||
func DeleteOrder(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *StoreApiController) DeleteOrder(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
orderId := params["orderId"]
|
||||
result, err := c.service.DeleteOrder(orderId)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// GetInventory - Returns pet inventories by status
|
||||
func GetInventory(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *StoreApiController) GetInventory(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := c.service.GetInventory()
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// GetOrderById - Find purchase order by ID
|
||||
func GetOrderById(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *StoreApiController) GetOrderById(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
orderId, err := parseIntParameter(params["orderId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.GetOrderById(orderId)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// PlaceOrder - Place an order for a pet
|
||||
func PlaceOrder(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *StoreApiController) PlaceOrder(w http.ResponseWriter, r *http.Request) {
|
||||
body := &Order{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.PlaceOrder(*body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* API version: 1.0.0
|
||||
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
||||
*/
|
||||
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// StoreApiService is a service that implents the logic for the StoreApiServicer
|
||||
// This service should implement the business logic for every endpoint for the StoreApi API.
|
||||
// Include any external packages or services that will be required by this service.
|
||||
type StoreApiService struct {
|
||||
}
|
||||
|
||||
// NewStoreApiService creates a default api service
|
||||
func NewStoreApiService() StoreApiServicer {
|
||||
return &StoreApiService{}
|
||||
}
|
||||
|
||||
// DeleteOrder - Delete purchase order by ID
|
||||
func (s *StoreApiService) DeleteOrder(orderId string) (interface{}, error) {
|
||||
// TODO - update DeleteOrder with the required logic for this service method.
|
||||
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'DeleteOrder' not implemented")
|
||||
}
|
||||
|
||||
// GetInventory - Returns pet inventories by status
|
||||
func (s *StoreApiService) GetInventory() (interface{}, error) {
|
||||
// TODO - update GetInventory with the required logic for this service method.
|
||||
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'GetInventory' not implemented")
|
||||
}
|
||||
|
||||
// GetOrderById - Find purchase order by ID
|
||||
func (s *StoreApiService) GetOrderById(orderId int64) (interface{}, error) {
|
||||
// TODO - update GetOrderById with the required logic for this service method.
|
||||
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'GetOrderById' not implemented")
|
||||
}
|
||||
|
||||
// PlaceOrder - Place an order for a pet
|
||||
func (s *StoreApiService) PlaceOrder(body Order) (interface{}, error) {
|
||||
// TODO - update PlaceOrder with the required logic for this service method.
|
||||
// Add api_store_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'PlaceOrder' not implemented")
|
||||
}
|
||||
@@ -10,53 +10,194 @@
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// A UserApiController binds http requests to an api service and writes the service results to the http response
|
||||
type UserApiController struct {
|
||||
service UserApiServicer
|
||||
}
|
||||
|
||||
// NewUserApiController creates a default api controller
|
||||
func NewUserApiController(s UserApiServicer) Router {
|
||||
return &UserApiController{ service: s }
|
||||
}
|
||||
|
||||
// Routes returns all of the api route for the UserApiController
|
||||
func (c *UserApiController) Routes() Routes {
|
||||
return Routes{
|
||||
{
|
||||
"CreateUser",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/user",
|
||||
c.CreateUser,
|
||||
},
|
||||
{
|
||||
"CreateUsersWithArrayInput",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/user/createWithArray",
|
||||
c.CreateUsersWithArrayInput,
|
||||
},
|
||||
{
|
||||
"CreateUsersWithListInput",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/user/createWithList",
|
||||
c.CreateUsersWithListInput,
|
||||
},
|
||||
{
|
||||
"DeleteUser",
|
||||
strings.ToUpper("Delete"),
|
||||
"/v2/user/{username}",
|
||||
c.DeleteUser,
|
||||
},
|
||||
{
|
||||
"GetUserByName",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/user/{username}",
|
||||
c.GetUserByName,
|
||||
},
|
||||
{
|
||||
"LoginUser",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/user/login",
|
||||
c.LoginUser,
|
||||
},
|
||||
{
|
||||
"LogoutUser",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/user/logout",
|
||||
c.LogoutUser,
|
||||
},
|
||||
{
|
||||
"UpdateUser",
|
||||
strings.ToUpper("Put"),
|
||||
"/v2/user/{username}",
|
||||
c.UpdateUser,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// CreateUser - Create user
|
||||
func CreateUser(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) CreateUser(w http.ResponseWriter, r *http.Request) {
|
||||
body := &User{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.CreateUser(*body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// CreateUsersWithArrayInput - Creates list of users with given input array
|
||||
func CreateUsersWithArrayInput(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) CreateUsersWithArrayInput(w http.ResponseWriter, r *http.Request) {
|
||||
body := &[]User{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.CreateUsersWithArrayInput(*body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// CreateUsersWithListInput - Creates list of users with given input array
|
||||
func CreateUsersWithListInput(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) CreateUsersWithListInput(w http.ResponseWriter, r *http.Request) {
|
||||
body := &[]User{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.CreateUsersWithListInput(*body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// DeleteUser - Delete user
|
||||
func DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
username := params["username"]
|
||||
result, err := c.service.DeleteUser(username)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// GetUserByName - Get user by user name
|
||||
func GetUserByName(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) GetUserByName(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
username := params["username"]
|
||||
result, err := c.service.GetUserByName(username)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// LoginUser - Logs user into the system
|
||||
func LoginUser(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) LoginUser(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
username := query.Get("username")
|
||||
password := query.Get("password")
|
||||
result, err := c.service.LoginUser(username, password)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// LogoutUser - Logs out current logged in user session
|
||||
func LogoutUser(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) LogoutUser(w http.ResponseWriter, r *http.Request) {
|
||||
result, err := c.service.LogoutUser()
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
// UpdateUser - Updated user
|
||||
func UpdateUser(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
func (c *UserApiController) UpdateUser(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
username := params["username"]
|
||||
body := &User{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.UpdateUser(username, *body)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
EncodeJSONResponse(result, nil, w)
|
||||
}
|
||||
|
||||
81
samples/server/petstore/go-api-server/go/api_user_service.go
Normal file
81
samples/server/petstore/go-api-server/go/api_user_service.go
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* API version: 1.0.0
|
||||
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
||||
*/
|
||||
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// UserApiService is a service that implents the logic for the UserApiServicer
|
||||
// This service should implement the business logic for every endpoint for the UserApi API.
|
||||
// Include any external packages or services that will be required by this service.
|
||||
type UserApiService struct {
|
||||
}
|
||||
|
||||
// NewUserApiService creates a default api service
|
||||
func NewUserApiService() UserApiServicer {
|
||||
return &UserApiService{}
|
||||
}
|
||||
|
||||
// CreateUser - Create user
|
||||
func (s *UserApiService) CreateUser(body User) (interface{}, error) {
|
||||
// TODO - update CreateUser with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'CreateUser' not implemented")
|
||||
}
|
||||
|
||||
// CreateUsersWithArrayInput - Creates list of users with given input array
|
||||
func (s *UserApiService) CreateUsersWithArrayInput(body []User) (interface{}, error) {
|
||||
// TODO - update CreateUsersWithArrayInput with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'CreateUsersWithArrayInput' not implemented")
|
||||
}
|
||||
|
||||
// CreateUsersWithListInput - Creates list of users with given input array
|
||||
func (s *UserApiService) CreateUsersWithListInput(body []User) (interface{}, error) {
|
||||
// TODO - update CreateUsersWithListInput with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'CreateUsersWithListInput' not implemented")
|
||||
}
|
||||
|
||||
// DeleteUser - Delete user
|
||||
func (s *UserApiService) DeleteUser(username string) (interface{}, error) {
|
||||
// TODO - update DeleteUser with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'DeleteUser' not implemented")
|
||||
}
|
||||
|
||||
// GetUserByName - Get user by user name
|
||||
func (s *UserApiService) GetUserByName(username string) (interface{}, error) {
|
||||
// TODO - update GetUserByName with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'GetUserByName' not implemented")
|
||||
}
|
||||
|
||||
// LoginUser - Logs user into the system
|
||||
func (s *UserApiService) LoginUser(username string, password string) (interface{}, error) {
|
||||
// TODO - update LoginUser with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'LoginUser' not implemented")
|
||||
}
|
||||
|
||||
// LogoutUser - Logs out current logged in user session
|
||||
func (s *UserApiService) LogoutUser() (interface{}, error) {
|
||||
// TODO - update LogoutUser with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'LogoutUser' not implemented")
|
||||
}
|
||||
|
||||
// UpdateUser - Updated user
|
||||
func (s *UserApiService) UpdateUser(username string, body User) (interface{}, error) {
|
||||
// TODO - update UpdateUser with the required logic for this service method.
|
||||
// Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||
return nil, errors.New("service method 'UpdateUser' not implemented")
|
||||
}
|
||||
@@ -10,13 +10,16 @@
|
||||
package petstoreserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// A Route defines the parameters for an api endpoint
|
||||
type Route struct {
|
||||
Name string
|
||||
Method string
|
||||
@@ -24,174 +27,71 @@ type Route struct {
|
||||
HandlerFunc http.HandlerFunc
|
||||
}
|
||||
|
||||
// Routes are a collection of defined api endpoints
|
||||
type Routes []Route
|
||||
|
||||
func NewRouter() *mux.Router {
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
for _, route := range routes {
|
||||
var handler http.Handler
|
||||
handler = route.HandlerFunc
|
||||
handler = Logger(handler, route.Name)
|
||||
// Router defines the required methods for retrieving api routes
|
||||
type Router interface {
|
||||
Routes() Routes
|
||||
}
|
||||
|
||||
router.
|
||||
Methods(route.Method).
|
||||
Path(route.Pattern).
|
||||
Name(route.Name).
|
||||
Handler(handler)
|
||||
// NewRouter creates a new router for any number of api routers
|
||||
func NewRouter(routers ...Router) *mux.Router {
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
for _, api := range routers {
|
||||
for _, route := range api.Routes() {
|
||||
var handler http.Handler
|
||||
handler = route.HandlerFunc
|
||||
handler = Logger(handler, route.Name)
|
||||
|
||||
router.
|
||||
Methods(route.Method).
|
||||
Path(route.Pattern).
|
||||
Name(route.Name).
|
||||
Handler(handler)
|
||||
}
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
func Index(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello World!")
|
||||
// EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
|
||||
func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
if status != nil {
|
||||
w.WriteHeader(*status)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
return json.NewEncoder(w).Encode(i)
|
||||
}
|
||||
|
||||
var routes = Routes{
|
||||
{
|
||||
"Index",
|
||||
"GET",
|
||||
"/v2/",
|
||||
Index,
|
||||
},
|
||||
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
||||
func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error) {
|
||||
r.ParseForm()
|
||||
formFile, _, err := r.FormFile(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
{
|
||||
"AddPet",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/pet",
|
||||
AddPet,
|
||||
},
|
||||
defer formFile.Close()
|
||||
file, err := ioutil.TempFile("tmp", key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
{
|
||||
"DeletePet",
|
||||
strings.ToUpper("Delete"),
|
||||
"/v2/pet/{petId}",
|
||||
DeletePet,
|
||||
},
|
||||
defer file.Close()
|
||||
fileBytes, err := ioutil.ReadAll(formFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
{
|
||||
"FindPetsByStatus",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/pet/findByStatus",
|
||||
FindPetsByStatus,
|
||||
},
|
||||
|
||||
{
|
||||
"FindPetsByTags",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/pet/findByTags",
|
||||
FindPetsByTags,
|
||||
},
|
||||
|
||||
{
|
||||
"GetPetById",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/pet/{petId}",
|
||||
GetPetById,
|
||||
},
|
||||
|
||||
{
|
||||
"UpdatePet",
|
||||
strings.ToUpper("Put"),
|
||||
"/v2/pet",
|
||||
UpdatePet,
|
||||
},
|
||||
|
||||
{
|
||||
"UpdatePetWithForm",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/pet/{petId}",
|
||||
UpdatePetWithForm,
|
||||
},
|
||||
|
||||
{
|
||||
"UploadFile",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/pet/{petId}/uploadImage",
|
||||
UploadFile,
|
||||
},
|
||||
|
||||
{
|
||||
"DeleteOrder",
|
||||
strings.ToUpper("Delete"),
|
||||
"/v2/store/order/{orderId}",
|
||||
DeleteOrder,
|
||||
},
|
||||
|
||||
{
|
||||
"GetInventory",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/store/inventory",
|
||||
GetInventory,
|
||||
},
|
||||
|
||||
{
|
||||
"GetOrderById",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/store/order/{orderId}",
|
||||
GetOrderById,
|
||||
},
|
||||
|
||||
{
|
||||
"PlaceOrder",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/store/order",
|
||||
PlaceOrder,
|
||||
},
|
||||
|
||||
{
|
||||
"CreateUser",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/user",
|
||||
CreateUser,
|
||||
},
|
||||
|
||||
{
|
||||
"CreateUsersWithArrayInput",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/user/createWithArray",
|
||||
CreateUsersWithArrayInput,
|
||||
},
|
||||
|
||||
{
|
||||
"CreateUsersWithListInput",
|
||||
strings.ToUpper("Post"),
|
||||
"/v2/user/createWithList",
|
||||
CreateUsersWithListInput,
|
||||
},
|
||||
|
||||
{
|
||||
"DeleteUser",
|
||||
strings.ToUpper("Delete"),
|
||||
"/v2/user/{username}",
|
||||
DeleteUser,
|
||||
},
|
||||
|
||||
{
|
||||
"GetUserByName",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/user/{username}",
|
||||
GetUserByName,
|
||||
},
|
||||
|
||||
{
|
||||
"LoginUser",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/user/login",
|
||||
LoginUser,
|
||||
},
|
||||
|
||||
{
|
||||
"LogoutUser",
|
||||
strings.ToUpper("Get"),
|
||||
"/v2/user/logout",
|
||||
LogoutUser,
|
||||
},
|
||||
|
||||
{
|
||||
"UpdateUser",
|
||||
strings.ToUpper("Put"),
|
||||
"/v2/user/{username}",
|
||||
UpdateUser,
|
||||
},
|
||||
file.Write(fileBytes)
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// parseIntParameter parses a sting parameter to an int64
|
||||
func parseIntParameter(param string) (int64, error) {
|
||||
return strconv.ParseInt(param, 10, 64)
|
||||
}
|
||||
|
||||
@@ -20,13 +20,22 @@ import (
|
||||
//
|
||||
// sw "github.com/myname/myrepo/go"
|
||||
//
|
||||
sw "./go"
|
||||
petstoreserver "./go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Printf("Server started")
|
||||
|
||||
router := sw.NewRouter()
|
||||
PetApiService := petstoreserver.NewPetApiService()
|
||||
PetApiController := petstoreserver.NewPetApiController(PetApiService)
|
||||
|
||||
StoreApiService := petstoreserver.NewStoreApiService()
|
||||
StoreApiController := petstoreserver.NewStoreApiController(StoreApiService)
|
||||
|
||||
UserApiService := petstoreserver.NewUserApiService()
|
||||
UserApiController := petstoreserver.NewUserApiController(UserApiService)
|
||||
|
||||
router := petstoreserver.NewRouter(PetApiController, StoreApiController, UserApiController)
|
||||
|
||||
log.Fatal(http.ListenAndServe(":8080", router))
|
||||
}
|
||||
|
||||
61
samples/server/petstore/go-api-server/pom.xml
Normal file
61
samples/server/petstore/go-api-server/pom.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>GoApiServer</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Go Api Server</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>gofmt-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>gofmt</executable>
|
||||
<arguments>
|
||||
<argument>-w</argument>
|
||||
<argument>./main.go</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>gofmt-file-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>gofmt</executable>
|
||||
<arguments>
|
||||
<argument>-w</argument>
|
||||
<argument>./go/</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Reference in New Issue
Block a user