gorest

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 5 Imported by: 0

README

gorest

Quickly build RESTful APIs in Go with auto-generated OpenAPI 3.1 documentation.

Quickstart

package main

import (
    "context"
    "log"
    "net/http"

    "github.com/kaptika/common/types"
    "github.com/kaptika/gorest"
)

func sayHello(ctx context.Context, req *types.Empty) (*types.BasicResponse, error) {
    return &types.BasicResponse{
        Message: "Hello, World!",
    }, nil
}

func main() {
    server := gorest.New(gorest.Config{
        Info: gorest.Info{
            Title:       "My API",
            Description: "This is a sample server.",
            Version:     "1.0.0",
        },
        URLs: []string{"http://localhost:3000"},
    })

    gorest.Add(server, http.MethodGet, "/hello", sayHello)

    log.Fatal(server.Start())
}

Then, run the program:

go run server.go

Browse to http://localhost:3000/docs and the OpenAPI documentation should be displayed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[I, O any](
	server *Server,
	method string,
	path string,
	f func(context.Context, *I) (*O, error),
)

Types

type Config

type Config struct {
	Listener
	Info Info
	URLs []string
}

type Info

type Info struct {
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Version     string `json:"version"`
}

type Listener

type Listener struct {
	Host string
	Port int
}

type OpenAPI

type OpenAPI struct {
	Reflector *openapi31.Reflector
}

type Server

type Server struct {
	FiberApp *fiber.App
	Config   Config
	OpenAPI  OpenAPI
}

func New

func New(config Config) *Server

func (*Server) Shutdown

func (s *Server) Shutdown() error

func (*Server) Start

func (s *Server) Start() error

Directories

Path Synopsis
examples
basic command

Jump to

Keyboard shortcuts

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