FINAL: CLI model. Also: changed 'clock' to 'time' or 'timeofday', depending.
This commit is contained in:
parent
24e408b58f
commit
7ed37720fc
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
errors "github.com/go-openapi/errors"
|
||||
runtime "github.com/go-openapi/runtime"
|
||||
swag "github.com/go-openapi/swag"
|
||||
graceful "github.com/tylerb/graceful"
|
||||
|
||||
"github.com/elfsternberg/timeofday/restapi/operations"
|
||||
|
@ -16,8 +17,17 @@ import (
|
|||
|
||||
//go:generate swagger generate server --target .. --name --spec ../swagger.yml
|
||||
|
||||
var Timezone = timeofday.Timezone{
|
||||
Timezone: "UTC",
|
||||
}
|
||||
|
||||
func configureFlags(api *operations.TimeofdayAPI) {
|
||||
// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
|
||||
api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{
|
||||
swag.CommandLineOptionsGroup{
|
||||
ShortDescription: "Time Of Day Service Options",
|
||||
Options: &Timezone,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func configureAPI(api *operations.TimeofdayAPI) http.Handler {
|
||||
|
@ -34,8 +44,8 @@ func configureAPI(api *operations.TimeofdayAPI) http.Handler {
|
|||
|
||||
api.JSONProducer = runtime.JSONProducer()
|
||||
|
||||
api.ClockGetHandler = operations.ClockGetHandlerFunc(timeofday.GetClock)
|
||||
api.ClockPostHandler = operations.ClockPostHandlerFunc(timeofday.PostClock)
|
||||
api.TimeGetHandler = operations.TimeGetHandlerFunc(timeofday.GetTime(&Timezone))
|
||||
api.TimePostHandler = operations.TimePostHandlerFunc(timeofday.PostTime(&Timezone))
|
||||
|
||||
api.ServerShutdown = func() {}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ func init() {
|
|||
"/time": {
|
||||
"get": {
|
||||
"description": "Returns time of day.",
|
||||
"operationId": "ClockGet",
|
||||
"operationId": "TimeGet",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
|
@ -78,7 +78,7 @@ func init() {
|
|||
},
|
||||
"post": {
|
||||
"description": "Returns time of day.",
|
||||
"operationId": "ClockPost",
|
||||
"operationId": "TimePost",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Timezone to return",
|
||||
|
@ -180,7 +180,7 @@ func init() {
|
|||
"/time": {
|
||||
"get": {
|
||||
"description": "Returns time of day.",
|
||||
"operationId": "ClockGet",
|
||||
"operationId": "TimeGet",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
|
@ -212,7 +212,7 @@ func init() {
|
|||
},
|
||||
"post": {
|
||||
"description": "Returns time of day.",
|
||||
"operationId": "ClockPost",
|
||||
"operationId": "TimePost",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Timezone to return",
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
models "github.com/elfsternberg/timeofday/models"
|
||||
)
|
||||
|
||||
// ClockGetOKCode is the HTTP code returned for type ClockGetOK
|
||||
const ClockGetOKCode int = 200
|
||||
|
||||
/*ClockGetOK Returns the time of day.
|
||||
|
||||
swagger:response clockGetOK
|
||||
*/
|
||||
type ClockGetOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.Timeofday `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewClockGetOK creates ClockGetOK with default headers values
|
||||
func NewClockGetOK() *ClockGetOK {
|
||||
|
||||
return &ClockGetOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the clock get o k response
|
||||
func (o *ClockGetOK) WithPayload(payload *models.Timeofday) *ClockGetOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the clock get o k response
|
||||
func (o *ClockGetOK) SetPayload(payload *models.Timeofday) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ClockGetOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ClockGetNotFoundCode is the HTTP code returned for type ClockGetNotFound
|
||||
const ClockGetNotFoundCode int = 404
|
||||
|
||||
/*ClockGetNotFound Time zone not found
|
||||
|
||||
swagger:response clockGetNotFound
|
||||
*/
|
||||
type ClockGetNotFound struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewClockGetNotFound creates ClockGetNotFound with default headers values
|
||||
func NewClockGetNotFound() *ClockGetNotFound {
|
||||
|
||||
return &ClockGetNotFound{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the clock get not found response
|
||||
func (o *ClockGetNotFound) WithPayload(payload *models.ErrorResponse) *ClockGetNotFound {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the clock get not found response
|
||||
func (o *ClockGetNotFound) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ClockGetNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(404)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ClockGetInternalServerErrorCode is the HTTP code returned for type ClockGetInternalServerError
|
||||
const ClockGetInternalServerErrorCode int = 500
|
||||
|
||||
/*ClockGetInternalServerError Something has gone horribly wrong
|
||||
|
||||
swagger:response clockGetInternalServerError
|
||||
*/
|
||||
type ClockGetInternalServerError struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewClockGetInternalServerError creates ClockGetInternalServerError with default headers values
|
||||
func NewClockGetInternalServerError() *ClockGetInternalServerError {
|
||||
|
||||
return &ClockGetInternalServerError{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the clock get internal server error response
|
||||
func (o *ClockGetInternalServerError) WithPayload(payload *models.ErrorResponse) *ClockGetInternalServerError {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the clock get internal server error response
|
||||
func (o *ClockGetInternalServerError) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ClockGetInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(500)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
middleware "github.com/go-openapi/runtime/middleware"
|
||||
)
|
||||
|
||||
// ClockPostHandlerFunc turns a function with the right signature into a clock post handler
|
||||
type ClockPostHandlerFunc func(ClockPostParams) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn ClockPostHandlerFunc) Handle(params ClockPostParams) middleware.Responder {
|
||||
return fn(params)
|
||||
}
|
||||
|
||||
// ClockPostHandler interface for that can handle valid clock post params
|
||||
type ClockPostHandler interface {
|
||||
Handle(ClockPostParams) middleware.Responder
|
||||
}
|
||||
|
||||
// NewClockPost creates a new http.Handler for the clock post operation
|
||||
func NewClockPost(ctx *middleware.Context, handler ClockPostHandler) *ClockPost {
|
||||
return &ClockPost{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/*ClockPost swagger:route POST /time clockPost
|
||||
|
||||
Returns time of day.
|
||||
|
||||
*/
|
||||
type ClockPost struct {
|
||||
Context *middleware.Context
|
||||
Handler ClockPostHandler
|
||||
}
|
||||
|
||||
func (o *ClockPost) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
r = rCtx
|
||||
}
|
||||
var Params = NewClockPostParams()
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
||||
res := o.Handler.Handle(Params) // actually handle the request
|
||||
|
||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
models "github.com/elfsternberg/timeofday/models"
|
||||
)
|
||||
|
||||
// ClockPostOKCode is the HTTP code returned for type ClockPostOK
|
||||
const ClockPostOKCode int = 200
|
||||
|
||||
/*ClockPostOK Returns the time of day.
|
||||
|
||||
swagger:response clockPostOK
|
||||
*/
|
||||
type ClockPostOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.Timeofday `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewClockPostOK creates ClockPostOK with default headers values
|
||||
func NewClockPostOK() *ClockPostOK {
|
||||
|
||||
return &ClockPostOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the clock post o k response
|
||||
func (o *ClockPostOK) WithPayload(payload *models.Timeofday) *ClockPostOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the clock post o k response
|
||||
func (o *ClockPostOK) SetPayload(payload *models.Timeofday) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ClockPostOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ClockPostNotFoundCode is the HTTP code returned for type ClockPostNotFound
|
||||
const ClockPostNotFoundCode int = 404
|
||||
|
||||
/*ClockPostNotFound Time zone not found
|
||||
|
||||
swagger:response clockPostNotFound
|
||||
*/
|
||||
type ClockPostNotFound struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewClockPostNotFound creates ClockPostNotFound with default headers values
|
||||
func NewClockPostNotFound() *ClockPostNotFound {
|
||||
|
||||
return &ClockPostNotFound{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the clock post not found response
|
||||
func (o *ClockPostNotFound) WithPayload(payload *models.ErrorResponse) *ClockPostNotFound {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the clock post not found response
|
||||
func (o *ClockPostNotFound) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ClockPostNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(404)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ClockPostInternalServerErrorCode is the HTTP code returned for type ClockPostInternalServerError
|
||||
const ClockPostInternalServerErrorCode int = 500
|
||||
|
||||
/*ClockPostInternalServerError Something has gone horribly wrong
|
||||
|
||||
swagger:response clockPostInternalServerError
|
||||
*/
|
||||
type ClockPostInternalServerError struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewClockPostInternalServerError creates ClockPostInternalServerError with default headers values
|
||||
func NewClockPostInternalServerError() *ClockPostInternalServerError {
|
||||
|
||||
return &ClockPostInternalServerError{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the clock post internal server error response
|
||||
func (o *ClockPostInternalServerError) WithPayload(payload *models.ErrorResponse) *ClockPostInternalServerError {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the clock post internal server error response
|
||||
func (o *ClockPostInternalServerError) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ClockPostInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(500)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
middleware "github.com/go-openapi/runtime/middleware"
|
||||
)
|
||||
|
||||
// TimeGetHandlerFunc turns a function with the right signature into a time get handler
|
||||
type TimeGetHandlerFunc func(TimeGetParams) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn TimeGetHandlerFunc) Handle(params TimeGetParams) middleware.Responder {
|
||||
return fn(params)
|
||||
}
|
||||
|
||||
// TimeGetHandler interface for that can handle valid time get params
|
||||
type TimeGetHandler interface {
|
||||
Handle(TimeGetParams) middleware.Responder
|
||||
}
|
||||
|
||||
// NewTimeGet creates a new http.Handler for the time get operation
|
||||
func NewTimeGet(ctx *middleware.Context, handler TimeGetHandler) *TimeGet {
|
||||
return &TimeGet{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/*TimeGet swagger:route GET /time timeGet
|
||||
|
||||
Returns time of day.
|
||||
|
||||
*/
|
||||
type TimeGet struct {
|
||||
Context *middleware.Context
|
||||
Handler TimeGetHandler
|
||||
}
|
||||
|
||||
func (o *TimeGet) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
r = rCtx
|
||||
}
|
||||
var Params = NewTimeGetParams()
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
||||
res := o.Handler.Handle(Params) // actually handle the request
|
||||
|
||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||
|
||||
}
|
|
@ -15,18 +15,18 @@ import (
|
|||
strfmt "github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// NewClockGetParams creates a new ClockGetParams object
|
||||
// NewTimeGetParams creates a new TimeGetParams object
|
||||
// no default values defined in spec.
|
||||
func NewClockGetParams() ClockGetParams {
|
||||
func NewTimeGetParams() TimeGetParams {
|
||||
|
||||
return ClockGetParams{}
|
||||
return TimeGetParams{}
|
||||
}
|
||||
|
||||
// ClockGetParams contains all the bound params for the clock get operation
|
||||
// TimeGetParams contains all the bound params for the time get operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters ClockGet
|
||||
type ClockGetParams struct {
|
||||
// swagger:parameters TimeGet
|
||||
type TimeGetParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
@ -40,8 +40,8 @@ type ClockGetParams struct {
|
|||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
// for simple values it will use straight method calls.
|
||||
//
|
||||
// To ensure default values, the struct must have been initialized with NewClockGetParams() beforehand.
|
||||
func (o *ClockGetParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
// To ensure default values, the struct must have been initialized with NewTimeGetParams() beforehand.
|
||||
func (o *TimeGetParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
@ -59,7 +59,7 @@ func (o *ClockGetParams) BindRequest(r *http.Request, route *middleware.MatchedR
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *ClockGetParams) bindTimezone(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
func (o *TimeGetParams) bindTimezone(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
|
@ -0,0 +1,146 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
models "github.com/elfsternberg/timeofday/models"
|
||||
)
|
||||
|
||||
// TimeGetOKCode is the HTTP code returned for type TimeGetOK
|
||||
const TimeGetOKCode int = 200
|
||||
|
||||
/*TimeGetOK Returns the time of day.
|
||||
|
||||
swagger:response timeGetOK
|
||||
*/
|
||||
type TimeGetOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.Timeofday `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewTimeGetOK creates TimeGetOK with default headers values
|
||||
func NewTimeGetOK() *TimeGetOK {
|
||||
|
||||
return &TimeGetOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the time get o k response
|
||||
func (o *TimeGetOK) WithPayload(payload *models.Timeofday) *TimeGetOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the time get o k response
|
||||
func (o *TimeGetOK) SetPayload(payload *models.Timeofday) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TimeGetOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TimeGetNotFoundCode is the HTTP code returned for type TimeGetNotFound
|
||||
const TimeGetNotFoundCode int = 404
|
||||
|
||||
/*TimeGetNotFound Time zone not found
|
||||
|
||||
swagger:response timeGetNotFound
|
||||
*/
|
||||
type TimeGetNotFound struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewTimeGetNotFound creates TimeGetNotFound with default headers values
|
||||
func NewTimeGetNotFound() *TimeGetNotFound {
|
||||
|
||||
return &TimeGetNotFound{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the time get not found response
|
||||
func (o *TimeGetNotFound) WithPayload(payload *models.ErrorResponse) *TimeGetNotFound {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the time get not found response
|
||||
func (o *TimeGetNotFound) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TimeGetNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(404)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TimeGetInternalServerErrorCode is the HTTP code returned for type TimeGetInternalServerError
|
||||
const TimeGetInternalServerErrorCode int = 500
|
||||
|
||||
/*TimeGetInternalServerError Something has gone horribly wrong
|
||||
|
||||
swagger:response timeGetInternalServerError
|
||||
*/
|
||||
type TimeGetInternalServerError struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewTimeGetInternalServerError creates TimeGetInternalServerError with default headers values
|
||||
func NewTimeGetInternalServerError() *TimeGetInternalServerError {
|
||||
|
||||
return &TimeGetInternalServerError{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the time get internal server error response
|
||||
func (o *TimeGetInternalServerError) WithPayload(payload *models.ErrorResponse) *TimeGetInternalServerError {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the time get internal server error response
|
||||
func (o *TimeGetInternalServerError) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TimeGetInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(500)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,8 +11,8 @@ import (
|
|||
golangswaggerpaths "path"
|
||||
)
|
||||
|
||||
// ClockGetURL generates an URL for the clock get operation
|
||||
type ClockGetURL struct {
|
||||
// TimeGetURL generates an URL for the time get operation
|
||||
type TimeGetURL struct {
|
||||
Timezone *string
|
||||
|
||||
_basePath string
|
||||
|
@ -23,7 +23,7 @@ type ClockGetURL struct {
|
|||
// WithBasePath sets the base path for this url builder, only required when it's different from the
|
||||
// base path specified in the swagger spec.
|
||||
// When the value of the base path is an empty string
|
||||
func (o *ClockGetURL) WithBasePath(bp string) *ClockGetURL {
|
||||
func (o *TimeGetURL) WithBasePath(bp string) *TimeGetURL {
|
||||
o.SetBasePath(bp)
|
||||
return o
|
||||
}
|
||||
|
@ -31,12 +31,12 @@ func (o *ClockGetURL) WithBasePath(bp string) *ClockGetURL {
|
|||
// SetBasePath sets the base path for this url builder, only required when it's different from the
|
||||
// base path specified in the swagger spec.
|
||||
// When the value of the base path is an empty string
|
||||
func (o *ClockGetURL) SetBasePath(bp string) {
|
||||
func (o *TimeGetURL) SetBasePath(bp string) {
|
||||
o._basePath = bp
|
||||
}
|
||||
|
||||
// Build a url path and query string
|
||||
func (o *ClockGetURL) Build() (*url.URL, error) {
|
||||
func (o *TimeGetURL) Build() (*url.URL, error) {
|
||||
var result url.URL
|
||||
|
||||
var _path = "/time"
|
||||
|
@ -63,7 +63,7 @@ func (o *ClockGetURL) Build() (*url.URL, error) {
|
|||
}
|
||||
|
||||
// Must is a helper function to panic when the url builder returns an error
|
||||
func (o *ClockGetURL) Must(u *url.URL, err error) *url.URL {
|
||||
func (o *TimeGetURL) Must(u *url.URL, err error) *url.URL {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -74,17 +74,17 @@ func (o *ClockGetURL) Must(u *url.URL, err error) *url.URL {
|
|||
}
|
||||
|
||||
// String returns the string representation of the path with query string
|
||||
func (o *ClockGetURL) String() string {
|
||||
func (o *TimeGetURL) String() string {
|
||||
return o.Must(o.Build()).String()
|
||||
}
|
||||
|
||||
// BuildFull builds a full url with scheme, host, path and query string
|
||||
func (o *ClockGetURL) BuildFull(scheme, host string) (*url.URL, error) {
|
||||
func (o *TimeGetURL) BuildFull(scheme, host string) (*url.URL, error) {
|
||||
if scheme == "" {
|
||||
return nil, errors.New("scheme is required for a full url on ClockGetURL")
|
||||
return nil, errors.New("scheme is required for a full url on TimeGetURL")
|
||||
}
|
||||
if host == "" {
|
||||
return nil, errors.New("host is required for a full url on ClockGetURL")
|
||||
return nil, errors.New("host is required for a full url on TimeGetURL")
|
||||
}
|
||||
|
||||
base, err := o.Build()
|
||||
|
@ -98,6 +98,6 @@ func (o *ClockGetURL) BuildFull(scheme, host string) (*url.URL, error) {
|
|||
}
|
||||
|
||||
// StringFull returns the string representation of a complete url
|
||||
func (o *ClockGetURL) StringFull(scheme, host string) string {
|
||||
func (o *TimeGetURL) StringFull(scheme, host string) string {
|
||||
return o.Must(o.BuildFull(scheme, host)).String()
|
||||
}
|
|
@ -11,40 +11,40 @@ import (
|
|||
middleware "github.com/go-openapi/runtime/middleware"
|
||||
)
|
||||
|
||||
// ClockGetHandlerFunc turns a function with the right signature into a clock get handler
|
||||
type ClockGetHandlerFunc func(ClockGetParams) middleware.Responder
|
||||
// TimePostHandlerFunc turns a function with the right signature into a time post handler
|
||||
type TimePostHandlerFunc func(TimePostParams) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn ClockGetHandlerFunc) Handle(params ClockGetParams) middleware.Responder {
|
||||
func (fn TimePostHandlerFunc) Handle(params TimePostParams) middleware.Responder {
|
||||
return fn(params)
|
||||
}
|
||||
|
||||
// ClockGetHandler interface for that can handle valid clock get params
|
||||
type ClockGetHandler interface {
|
||||
Handle(ClockGetParams) middleware.Responder
|
||||
// TimePostHandler interface for that can handle valid time post params
|
||||
type TimePostHandler interface {
|
||||
Handle(TimePostParams) middleware.Responder
|
||||
}
|
||||
|
||||
// NewClockGet creates a new http.Handler for the clock get operation
|
||||
func NewClockGet(ctx *middleware.Context, handler ClockGetHandler) *ClockGet {
|
||||
return &ClockGet{Context: ctx, Handler: handler}
|
||||
// NewTimePost creates a new http.Handler for the time post operation
|
||||
func NewTimePost(ctx *middleware.Context, handler TimePostHandler) *TimePost {
|
||||
return &TimePost{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/*ClockGet swagger:route GET /time clockGet
|
||||
/*TimePost swagger:route POST /time timePost
|
||||
|
||||
Returns time of day.
|
||||
|
||||
*/
|
||||
type ClockGet struct {
|
||||
type TimePost struct {
|
||||
Context *middleware.Context
|
||||
Handler ClockGetHandler
|
||||
Handler TimePostHandler
|
||||
}
|
||||
|
||||
func (o *ClockGet) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
func (o *TimePost) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
r = rCtx
|
||||
}
|
||||
var Params = NewClockGetParams()
|
||||
var Params = NewTimePostParams()
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
|
@ -15,18 +15,18 @@ import (
|
|||
models "github.com/elfsternberg/timeofday/models"
|
||||
)
|
||||
|
||||
// NewClockPostParams creates a new ClockPostParams object
|
||||
// NewTimePostParams creates a new TimePostParams object
|
||||
// no default values defined in spec.
|
||||
func NewClockPostParams() ClockPostParams {
|
||||
func NewTimePostParams() TimePostParams {
|
||||
|
||||
return ClockPostParams{}
|
||||
return TimePostParams{}
|
||||
}
|
||||
|
||||
// ClockPostParams contains all the bound params for the clock post operation
|
||||
// TimePostParams contains all the bound params for the time post operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters ClockPost
|
||||
type ClockPostParams struct {
|
||||
// swagger:parameters TimePost
|
||||
type TimePostParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
@ -40,8 +40,8 @@ type ClockPostParams struct {
|
|||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
// for simple values it will use straight method calls.
|
||||
//
|
||||
// To ensure default values, the struct must have been initialized with NewClockPostParams() beforehand.
|
||||
func (o *ClockPostParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
// To ensure default values, the struct must have been initialized with NewTimePostParams() beforehand.
|
||||
func (o *TimePostParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
|
@ -0,0 +1,146 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package operations
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
models "github.com/elfsternberg/timeofday/models"
|
||||
)
|
||||
|
||||
// TimePostOKCode is the HTTP code returned for type TimePostOK
|
||||
const TimePostOKCode int = 200
|
||||
|
||||
/*TimePostOK Returns the time of day.
|
||||
|
||||
swagger:response timePostOK
|
||||
*/
|
||||
type TimePostOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.Timeofday `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewTimePostOK creates TimePostOK with default headers values
|
||||
func NewTimePostOK() *TimePostOK {
|
||||
|
||||
return &TimePostOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the time post o k response
|
||||
func (o *TimePostOK) WithPayload(payload *models.Timeofday) *TimePostOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the time post o k response
|
||||
func (o *TimePostOK) SetPayload(payload *models.Timeofday) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TimePostOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TimePostNotFoundCode is the HTTP code returned for type TimePostNotFound
|
||||
const TimePostNotFoundCode int = 404
|
||||
|
||||
/*TimePostNotFound Time zone not found
|
||||
|
||||
swagger:response timePostNotFound
|
||||
*/
|
||||
type TimePostNotFound struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewTimePostNotFound creates TimePostNotFound with default headers values
|
||||
func NewTimePostNotFound() *TimePostNotFound {
|
||||
|
||||
return &TimePostNotFound{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the time post not found response
|
||||
func (o *TimePostNotFound) WithPayload(payload *models.ErrorResponse) *TimePostNotFound {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the time post not found response
|
||||
func (o *TimePostNotFound) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TimePostNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(404)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TimePostInternalServerErrorCode is the HTTP code returned for type TimePostInternalServerError
|
||||
const TimePostInternalServerErrorCode int = 500
|
||||
|
||||
/*TimePostInternalServerError Something has gone horribly wrong
|
||||
|
||||
swagger:response timePostInternalServerError
|
||||
*/
|
||||
type TimePostInternalServerError struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ErrorResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewTimePostInternalServerError creates TimePostInternalServerError with default headers values
|
||||
func NewTimePostInternalServerError() *TimePostInternalServerError {
|
||||
|
||||
return &TimePostInternalServerError{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the time post internal server error response
|
||||
func (o *TimePostInternalServerError) WithPayload(payload *models.ErrorResponse) *TimePostInternalServerError {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the time post internal server error response
|
||||
func (o *TimePostInternalServerError) SetPayload(payload *models.ErrorResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *TimePostInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(500)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,15 +11,15 @@ import (
|
|||
golangswaggerpaths "path"
|
||||
)
|
||||
|
||||
// ClockPostURL generates an URL for the clock post operation
|
||||
type ClockPostURL struct {
|
||||
// TimePostURL generates an URL for the time post operation
|
||||
type TimePostURL struct {
|
||||
_basePath string
|
||||
}
|
||||
|
||||
// WithBasePath sets the base path for this url builder, only required when it's different from the
|
||||
// base path specified in the swagger spec.
|
||||
// When the value of the base path is an empty string
|
||||
func (o *ClockPostURL) WithBasePath(bp string) *ClockPostURL {
|
||||
func (o *TimePostURL) WithBasePath(bp string) *TimePostURL {
|
||||
o.SetBasePath(bp)
|
||||
return o
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ func (o *ClockPostURL) WithBasePath(bp string) *ClockPostURL {
|
|||
// SetBasePath sets the base path for this url builder, only required when it's different from the
|
||||
// base path specified in the swagger spec.
|
||||
// When the value of the base path is an empty string
|
||||
func (o *ClockPostURL) SetBasePath(bp string) {
|
||||
func (o *TimePostURL) SetBasePath(bp string) {
|
||||
o._basePath = bp
|
||||
}
|
||||
|
||||
// Build a url path and query string
|
||||
func (o *ClockPostURL) Build() (*url.URL, error) {
|
||||
func (o *TimePostURL) Build() (*url.URL, error) {
|
||||
var result url.URL
|
||||
|
||||
var _path = "/time"
|
||||
|
@ -47,7 +47,7 @@ func (o *ClockPostURL) Build() (*url.URL, error) {
|
|||
}
|
||||
|
||||
// Must is a helper function to panic when the url builder returns an error
|
||||
func (o *ClockPostURL) Must(u *url.URL, err error) *url.URL {
|
||||
func (o *TimePostURL) Must(u *url.URL, err error) *url.URL {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -58,17 +58,17 @@ func (o *ClockPostURL) Must(u *url.URL, err error) *url.URL {
|
|||
}
|
||||
|
||||
// String returns the string representation of the path with query string
|
||||
func (o *ClockPostURL) String() string {
|
||||
func (o *TimePostURL) String() string {
|
||||
return o.Must(o.Build()).String()
|
||||
}
|
||||
|
||||
// BuildFull builds a full url with scheme, host, path and query string
|
||||
func (o *ClockPostURL) BuildFull(scheme, host string) (*url.URL, error) {
|
||||
func (o *TimePostURL) BuildFull(scheme, host string) (*url.URL, error) {
|
||||
if scheme == "" {
|
||||
return nil, errors.New("scheme is required for a full url on ClockPostURL")
|
||||
return nil, errors.New("scheme is required for a full url on TimePostURL")
|
||||
}
|
||||
if host == "" {
|
||||
return nil, errors.New("host is required for a full url on ClockPostURL")
|
||||
return nil, errors.New("host is required for a full url on TimePostURL")
|
||||
}
|
||||
|
||||
base, err := o.Build()
|
||||
|
@ -82,6 +82,6 @@ func (o *ClockPostURL) BuildFull(scheme, host string) (*url.URL, error) {
|
|||
}
|
||||
|
||||
// StringFull returns the string representation of a complete url
|
||||
func (o *ClockPostURL) StringFull(scheme, host string) string {
|
||||
func (o *TimePostURL) StringFull(scheme, host string) string {
|
||||
return o.Must(o.BuildFull(scheme, host)).String()
|
||||
}
|
|
@ -37,11 +37,11 @@ func NewTimeofdayAPI(spec *loads.Document) *TimeofdayAPI {
|
|||
BearerAuthenticator: security.BearerAuth,
|
||||
JSONConsumer: runtime.JSONConsumer(),
|
||||
JSONProducer: runtime.JSONProducer(),
|
||||
ClockGetHandler: ClockGetHandlerFunc(func(params ClockGetParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation ClockGet has not yet been implemented")
|
||||
TimeGetHandler: TimeGetHandlerFunc(func(params TimeGetParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation TimeGet has not yet been implemented")
|
||||
}),
|
||||
ClockPostHandler: ClockPostHandlerFunc(func(params ClockPostParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation ClockPost has not yet been implemented")
|
||||
TimePostHandler: TimePostHandlerFunc(func(params TimePostParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation TimePost has not yet been implemented")
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +74,10 @@ type TimeofdayAPI struct {
|
|||
// JSONProducer registers a producer for a "application/json" mime type
|
||||
JSONProducer runtime.Producer
|
||||
|
||||
// ClockGetHandler sets the operation handler for the clock get operation
|
||||
ClockGetHandler ClockGetHandler
|
||||
// ClockPostHandler sets the operation handler for the clock post operation
|
||||
ClockPostHandler ClockPostHandler
|
||||
// TimeGetHandler sets the operation handler for the time get operation
|
||||
TimeGetHandler TimeGetHandler
|
||||
// TimePostHandler sets the operation handler for the time post operation
|
||||
TimePostHandler TimePostHandler
|
||||
|
||||
// ServeError is called when an error is received, there is a default handler
|
||||
// but you can set your own with this
|
||||
|
@ -141,12 +141,12 @@ func (o *TimeofdayAPI) Validate() error {
|
|||
unregistered = append(unregistered, "JSONProducer")
|
||||
}
|
||||
|
||||
if o.ClockGetHandler == nil {
|
||||
unregistered = append(unregistered, "ClockGetHandler")
|
||||
if o.TimeGetHandler == nil {
|
||||
unregistered = append(unregistered, "TimeGetHandler")
|
||||
}
|
||||
|
||||
if o.ClockPostHandler == nil {
|
||||
unregistered = append(unregistered, "ClockPostHandler")
|
||||
if o.TimePostHandler == nil {
|
||||
unregistered = append(unregistered, "TimePostHandler")
|
||||
}
|
||||
|
||||
if len(unregistered) > 0 {
|
||||
|
@ -250,12 +250,12 @@ func (o *TimeofdayAPI) initHandlerCache() {
|
|||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["GET"]["/time"] = NewClockGet(o.context, o.ClockGetHandler)
|
||||
o.handlers["GET"]["/time"] = NewTimeGet(o.context, o.TimeGetHandler)
|
||||
|
||||
if o.handlers["POST"] == nil {
|
||||
o.handlers["POST"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["POST"]["/time"] = NewClockPost(o.context, o.ClockPostHandler)
|
||||
o.handlers["POST"]["/time"] = NewTimePost(o.context, o.TimePostHandler)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,15 +11,8 @@ import(
|
|||
)
|
||||
|
||||
|
||||
|
||||
func getTimeOfDay(tz *string) (*string, error) {
|
||||
defaultTZ := "UTC"
|
||||
|
||||
t := time.Now()
|
||||
if tz == nil {
|
||||
tz = &defaultTZ
|
||||
}
|
||||
|
||||
utc, err := time.LoadLocation(*tz)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Time zone not found: %s", *tz))
|
||||
|
@ -30,47 +23,52 @@ func getTimeOfDay(tz *string) (*string, error) {
|
|||
}
|
||||
|
||||
|
||||
func GetClock(params operations.ClockGetParams) middleware.Responder {
|
||||
var tz *string = nil
|
||||
func GetTime(timezone *Timezone) func(operations.TimeGetParams) middleware.Responder{
|
||||
defaultTZ := timezone.Timezone
|
||||
|
||||
return func(params operations.TimeGetParams) middleware.Responder {
|
||||
var tz *string = &defaultTZ
|
||||
if (params.Timezone != nil) {
|
||||
tz = params.Timezone
|
||||
}
|
||||
|
||||
thetime, err := getTimeOfDay(tz)
|
||||
if err != nil {
|
||||
return operations.NewClockGetNotFound().WithPayload(
|
||||
return operations.NewTimeGetNotFound().WithPayload(
|
||||
&models.ErrorResponse {
|
||||
int32(operations.ClockGetNotFoundCode),
|
||||
int32(operations.TimeGetNotFoundCode),
|
||||
swag.String(fmt.Sprintf("%s", err)),
|
||||
})
|
||||
}
|
||||
|
||||
return operations.NewClockGetOK().WithPayload(
|
||||
return operations.NewTimeGetOK().WithPayload(
|
||||
&models.Timeofday{
|
||||
Timeofday: *thetime,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func PostTime(timezone *Timezone) func(operations.TimePostParams) middleware.Responder{
|
||||
defaultTZ := timezone.Timezone
|
||||
|
||||
func PostClock(params operations.ClockPostParams) middleware.Responder {
|
||||
var tz *string = nil
|
||||
|
||||
return func(params operations.TimePostParams) middleware.Responder {
|
||||
var tz *string = &defaultTZ
|
||||
if (params.Timezone != nil) {
|
||||
tz = params.Timezone.Timezone
|
||||
}
|
||||
|
||||
thetime, err := getTimeOfDay(tz)
|
||||
if err != nil {
|
||||
return operations.NewClockPostNotFound().WithPayload(
|
||||
return operations.NewTimePostNotFound().WithPayload(
|
||||
&models.ErrorResponse {
|
||||
int32(operations.ClockPostNotFoundCode),
|
||||
int32(operations.TimePostNotFoundCode),
|
||||
swag.String(fmt.Sprintf("%s", err)),
|
||||
})
|
||||
}
|
||||
|
||||
return operations.NewClockPostOK().WithPayload(
|
||||
return operations.NewTimePostOK().WithPayload(
|
||||
&models.Timeofday{
|
||||
Timeofday: *thetime,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package timeofday
|
||||
|
||||
type Timezone struct {
|
||||
Timezone string `long:"timezone" short:"t" description:"The default time zone" env:"GOTIME_DEFAULT_TIMEZONE" default:"UTC"`
|
||||
}
|
Loading…
Reference in New Issue