api

package
v0.0.0-...-ab52134 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetID

func GetID(r *http.Request) (int, error)

GetID is a helper function that returns the id from the url

func HandleCreateTodo

func HandleCreateTodo(s APIServer, w http.ResponseWriter, r *http.Request) error

HandleCreateTodo handles the POST request for creating new todos

func HandleCreateUser

func HandleCreateUser(s APIServer, w http.ResponseWriter, r *http.Request) error

func HandleDeleteTodo

func HandleDeleteTodo(s APIServer, w http.ResponseWriter, r *http.Request) error

HandleDeleteTodo handles the DELETE request for deleting todos

func HandleGetTodo

func HandleGetTodo(s APIServer, w http.ResponseWriter, r *http.Request) error

HandleGetTodo handles the GET request for fetching todos.

func HandleGetTodoByID

func HandleGetTodoByID(s APIServer, w http.ResponseWriter, r *http.Request) error

HandleGetTodoByID handles the GET request for getting all the todos

func HandleGetUser

func HandleGetUser(s APIServer, w http.ResponseWriter, r *http.Request) error

func HandleLogin

func HandleLogin(s APIServer, w http.ResponseWriter, r *http.Request) error

func HandleUpdateTodo

func HandleUpdateTodo(s APIServer, w http.ResponseWriter, r *http.Request) error

HandleUpdateTodo handles the PATCH request for updating the todos

func HandleUser

func HandleUser(s APIServer, w http.ResponseWriter, r *http.Request) error

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any) error

WriteJSON is a Helper function to return JSON response to ui

Types

type APIServer

type APIServer struct {
	Store postgres.Storage
	// contains filtered or unexported fields
}

APIServer represents the API server structure

func NewAPIServer

func NewAPIServer(listenAddr string, Store postgres.Storage) *APIServer

NewAPIServer creates a new instance of APIServer

func (*APIServer) RegisterRoutes

func (s *APIServer) RegisterRoutes()

RegisterRoutes starts the API server and listens for incoming requests.

type ApiError

type ApiError struct {
	Error string `json:"error"`
}

ApiError represents an error response in JSON format.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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