hourly

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 15 Imported by: 0

README

Hourly

REST API

The Hourly API is a REST API and includes an OpenAPI specification . It isn't published on the internet but can be run locally by using the following command:

go run github.com/dillendev/training-hourly/cmd/server@latest

This will run the Hourly API on port 8989 on localhost and contains the actual data for the assignment.

Go client

The Go client is a client for the Hourly API. It can be used to retrieve the data from the API and can be used to create a CLI or a web application. Note that it requires authorization by using a token. The token can be retrieved by using the /api/auth/tokens endpoint.

Usage
package main

import (
	"github.com/deepmap/oapi-codegen/pkg/securityprovider"
	hourly "github.com/dillendev/training-hourly"
)

func main() {
    // Setup bearer token authentication
	provider, err := securityprovider.NewSecurityProviderBearerToken("my-token")
	if err != nil {
		panic(err)
	}

	// Setup client-side middleware to add the authorization header
    authOption := hourly.WithRequestEditorFn(provider.Intercept)

	// Create a new client for the Hourly API with the middleware
	client, err := hourly.NewClientWithResponses("http://localhost:8989", authOption)
	if err != nil {
		panic(err)
	}

	// Do something with: client
}

Documentation

Overview

Package hourly provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.

Index

Constants

View Source
const (
	BearerAuthScopes = "bearerAuth.Scopes"
)

Variables

This section is empty.

Functions

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func NewCreateTokenRequest

func NewCreateTokenRequest(server string, body CreateTokenJSONRequestBody) (*http.Request, error)

NewCreateTokenRequest calls the generic CreateToken builder with application/json body

func NewCreateTokenRequestWithBody

func NewCreateTokenRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewCreateTokenRequestWithBody generates requests for CreateToken with any type of body

func NewListProjectsRequest added in v0.0.3

func NewListProjectsRequest(server string) (*http.Request, error)

NewListProjectsRequest generates requests for ListProjects

func NewListTimeEntriesRequest

func NewListTimeEntriesRequest(server string, userId int, params *ListTimeEntriesParams) (*http.Request, error)

NewListTimeEntriesRequest generates requests for ListTimeEntries

func NewListUsersRequest

func NewListUsersRequest(server string) (*http.Request, error)

NewListUsersRequest generates requests for ListUsers

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

func RegisterHandlers

func RegisterHandlers(router EchoRouter, si ServerInterface)

RegisterHandlers adds each server route to the EchoRouter.

func RegisterHandlersWithBaseURL

func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string)

Registers handlers, and prepends BaseURL to the paths, so that the paths can be served under a prefix.

Types

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) CreateToken

func (c *Client) CreateToken(ctx context.Context, body CreateTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) CreateTokenWithBody

func (c *Client) CreateTokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) ListProjects added in v0.0.3

func (c *Client) ListProjects(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) ListTimeEntries

func (c *Client) ListTimeEntries(ctx context.Context, userId int, params *ListTimeEntriesParams, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// CreateToken request with any body
	CreateTokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	CreateToken(ctx context.Context, body CreateTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// ListProjects request
	ListProjects(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// ListUsers request
	ListUsers(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// ListTimeEntries request
	ListTimeEntries(ctx context.Context, userId int, params *ListTimeEntriesParams, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) CreateTokenWithBodyWithResponse

func (c *ClientWithResponses) CreateTokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateTokenResponse, error)

CreateTokenWithBodyWithResponse request with arbitrary body returning *CreateTokenResponse

func (*ClientWithResponses) CreateTokenWithResponse

func (c *ClientWithResponses) CreateTokenWithResponse(ctx context.Context, body CreateTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateTokenResponse, error)

func (*ClientWithResponses) ListProjectsWithResponse added in v0.0.3

func (c *ClientWithResponses) ListProjectsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListProjectsResponse, error)

ListProjectsWithResponse request returning *ListProjectsResponse

func (*ClientWithResponses) ListTimeEntriesWithResponse

func (c *ClientWithResponses) ListTimeEntriesWithResponse(ctx context.Context, userId int, params *ListTimeEntriesParams, reqEditors ...RequestEditorFn) (*ListTimeEntriesResponse, error)

ListTimeEntriesWithResponse request returning *ListTimeEntriesResponse

func (*ClientWithResponses) ListUsersWithResponse

func (c *ClientWithResponses) ListUsersWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListUsersResponse, error)

ListUsersWithResponse request returning *ListUsersResponse

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// CreateToken request with any body
	CreateTokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateTokenResponse, error)

	CreateTokenWithResponse(ctx context.Context, body CreateTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateTokenResponse, error)

	// ListProjects request
	ListProjectsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListProjectsResponse, error)

	// ListUsers request
	ListUsersWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListUsersResponse, error)

	// ListTimeEntries request
	ListTimeEntriesWithResponse(ctx context.Context, userId int, params *ListTimeEntriesParams, reqEditors ...RequestEditorFn) (*ListTimeEntriesResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type CreateTokenJSONRequestBody

type CreateTokenJSONRequestBody = TokenRequest

CreateTokenJSONRequestBody defines body for CreateToken for application/json ContentType.

type CreateTokenResponse

type CreateTokenResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *TokenResponse
	JSON400      *Error
	JSON500      *Error
}

func ParseCreateTokenResponse

func ParseCreateTokenResponse(rsp *http.Response) (*CreateTokenResponse, error)

ParseCreateTokenResponse parses an HTTP response from a CreateTokenWithResponse call

func (CreateTokenResponse) Status

func (r CreateTokenResponse) Status() string

Status returns HTTPResponse.Status

func (CreateTokenResponse) StatusCode

func (r CreateTokenResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type EchoRouter

type EchoRouter interface {
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

This is a simple interface which specifies echo.Route addition functions which are present on both echo.Echo and echo.Group, since we want to allow using either of them for path registration

type Error

type Error struct {
	Message string `json:"message"`
}

Error defines model for Error.

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type ListProjectsResponse added in v0.0.3

type ListProjectsResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]Project
	JSON400      *Error
}

func ParseListProjectsResponse added in v0.0.3

func ParseListProjectsResponse(rsp *http.Response) (*ListProjectsResponse, error)

ParseListProjectsResponse parses an HTTP response from a ListProjectsWithResponse call

func (ListProjectsResponse) Status added in v0.0.3

func (r ListProjectsResponse) Status() string

Status returns HTTPResponse.Status

func (ListProjectsResponse) StatusCode added in v0.0.3

func (r ListProjectsResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type ListTimeEntriesParams

type ListTimeEntriesParams struct {
	// StartDate Start date
	StartDate *time.Time `form:"startDate,omitempty" json:"startDate,omitempty"`

	// EndDate End date
	EndDate *time.Time `form:"endDate,omitempty" json:"endDate,omitempty"`
}

ListTimeEntriesParams defines parameters for ListTimeEntries.

type ListTimeEntriesResponse

type ListTimeEntriesResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]TimeEntry
	JSON400      *Error
	JSON404      *Error
}

func ParseListTimeEntriesResponse

func ParseListTimeEntriesResponse(rsp *http.Response) (*ListTimeEntriesResponse, error)

ParseListTimeEntriesResponse parses an HTTP response from a ListTimeEntriesWithResponse call

func (ListTimeEntriesResponse) Status

func (r ListTimeEntriesResponse) Status() string

Status returns HTTPResponse.Status

func (ListTimeEntriesResponse) StatusCode

func (r ListTimeEntriesResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type ListUsersResponse

type ListUsersResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]User
	JSON400      *Error
}

func ParseListUsersResponse

func ParseListUsersResponse(rsp *http.Response) (*ListUsersResponse, error)

ParseListUsersResponse parses an HTTP response from a ListUsersWithResponse call

func (ListUsersResponse) Status

func (r ListUsersResponse) Status() string

Status returns HTTPResponse.Status

func (ListUsersResponse) StatusCode

func (r ListUsersResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type Project

type Project struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

Project defines model for Project.

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type ServerInterface

type ServerInterface interface {
	// Returns a new authentication token
	// (POST /api/auth/tokens)
	CreateToken(ctx echo.Context) error
	// Returns a list of projects
	// (GET /api/projects)
	ListProjects(ctx echo.Context) error
	// Returns a list of users
	// (GET /api/users)
	ListUsers(ctx echo.Context) error
	// Returns a list of time entries
	// (GET /api/{userId}/time_entries)
	ListTimeEntries(ctx echo.Context, userId int, params ListTimeEntriesParams) error
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

ServerInterfaceWrapper converts echo contexts to parameters.

func (*ServerInterfaceWrapper) CreateToken

func (w *ServerInterfaceWrapper) CreateToken(ctx echo.Context) error

CreateToken converts echo context to params.

func (*ServerInterfaceWrapper) ListProjects added in v0.0.3

func (w *ServerInterfaceWrapper) ListProjects(ctx echo.Context) error

ListProjects converts echo context to params.

func (*ServerInterfaceWrapper) ListTimeEntries

func (w *ServerInterfaceWrapper) ListTimeEntries(ctx echo.Context) error

ListTimeEntries converts echo context to params.

func (*ServerInterfaceWrapper) ListUsers

func (w *ServerInterfaceWrapper) ListUsers(ctx echo.Context) error

ListUsers converts echo context to params.

type TimeEntry

type TimeEntry struct {
	At          string    `json:"at"`
	Billable    bool      `json:"billable"`
	Description *string   `json:"description,omitempty"`
	Id          int       `json:"id"`
	Project     Project   `json:"project"`
	StartedAt   time.Time `json:"startedAt"`
	StoppedAt   time.Time `json:"stoppedAt"`
}

TimeEntry defines model for TimeEntry.

type TokenRequest

type TokenRequest struct {
	PlatformId string `json:"platformId"`
}

TokenRequest defines model for TokenRequest.

type TokenResponse

type TokenResponse struct {
	Token string `json:"token"`
}

TokenResponse defines model for TokenResponse.

type User

type User struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
	Rate int    `json:"rate"`
}

User defines model for User.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL