mirror of
https://github.com/twhite96/go-backend-api.git
synced 2025-01-31 06:59:15 +00:00
Update something
This commit is contained in:
parent
915e44b69a
commit
498d446018
140
cmd/api/api-spec.yaml
Normal file
140
cmd/api/api-spec.yaml
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
openapi: 3.0.0
|
||||||
|
info:
|
||||||
|
title: Calculator API
|
||||||
|
version: 1.0.0
|
||||||
|
servers:
|
||||||
|
- url: http://localhost:3000
|
||||||
|
paths:
|
||||||
|
/add:
|
||||||
|
post:
|
||||||
|
summary: Add two numbers
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
number1:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
number2:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successfully added two numbers
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
/subtract:
|
||||||
|
post:
|
||||||
|
summary: Subtract two numbers
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
number1:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
number2:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successfully subtracted two numbers
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
/multiply:
|
||||||
|
post:
|
||||||
|
summary: Multiply two numbers
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
number1:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
number2:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successfully multiplied two numbers
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
/divide:
|
||||||
|
post:
|
||||||
|
summary: Divide two numbers
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
dividend:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
divisor:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successfully divided two numbers
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
|
||||||
|
/sum:
|
||||||
|
post:
|
||||||
|
summary: Add all numbers in an array
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: number
|
||||||
|
format: int
|
||||||
|
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successfully divided two numbers
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
result:
|
||||||
|
type: number
|
||||||
|
format: int
|
@ -3,31 +3,35 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
"github.com/pocketbase/pocketbase"
|
||||||
|
"github.com/pocketbase/pocketbase/apis"
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
|
|
||||||
"go-calc/internal/server"
|
"go-calc/internal/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
func gracefulShutdown(apiServer *http.Server, done chan bool) {
|
func gracefulShutdown(apiServer *http.Server, done chan bool) {
|
||||||
// Create context that listens for the interrupt signal from the OS.
|
// Create context that listens for the interrupt signal from the OS.
|
||||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||||
|
slog.InfoContext(ctx.Context, msg string, args ...any), stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
// Listen for the interrupt signal.
|
// Listen for the interrupt signal.
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|
||||||
log.Println("shutting down gracefully, press Ctrl+C again to force")
|
logger.Info("shutting down gracefully, press Ctrl+C again to force")
|
||||||
|
|
||||||
// The context is used to inform the server it has 5 seconds to finish
|
// The context is used to inform the server it has 5 seconds to finish
|
||||||
// the request it is currently handling
|
// the request it is currently handling
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if err := apiServer.Shutdown(ctx); err != nil {
|
if err := apiServer.Shutdown(ctx); err != nil {
|
||||||
log.Printf("Server forced to shutdown with error: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Server exiting")
|
log.Println("Server exiting")
|
||||||
|
2
go.mod
2
go.mod
@ -3,3 +3,5 @@ module go-calc
|
|||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
|
||||||
require github.com/joho/godotenv v1.5.1
|
require github.com/joho/godotenv v1.5.1
|
||||||
|
|
||||||
|
require github.com/rs/cors v1.11.1 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -1,2 +1,4 @@
|
|||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=
|
||||||
|
github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user