feat: Remove outdated Swagger documentation files and update database configuration handling
This commit is contained in:
parent
09584efa39
commit
a0b0b98624
6
.env
Normal file
6
.env
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
DB_HOST=localhost
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_USER=timetracker
|
||||||
|
DB_PASSWORD=password
|
||||||
|
DB_NAME=timetracker
|
||||||
|
DB_SSLMODE=disable
|
@ -1,62 +0,0 @@
|
|||||||
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
|
||||||
package docs
|
|
||||||
|
|
||||||
import "github.com/swaggo/swag"
|
|
||||||
|
|
||||||
const docTemplate = `{
|
|
||||||
"schemes": {{ marshal .Schemes }},
|
|
||||||
"swagger": "2.0",
|
|
||||||
"info": {
|
|
||||||
"description": "{{escape .Description}}",
|
|
||||||
"title": "{{.Title}}",
|
|
||||||
"contact": {},
|
|
||||||
"version": "{{.Version}}"
|
|
||||||
},
|
|
||||||
"host": "{{.Host}}",
|
|
||||||
"basePath": "{{.BasePath}}",
|
|
||||||
"paths": {
|
|
||||||
"/": {
|
|
||||||
"get": {
|
|
||||||
"description": "Get a hello message",
|
|
||||||
"produces": [
|
|
||||||
"text/plain"
|
|
||||||
],
|
|
||||||
"summary": "Say hello",
|
|
||||||
"operationId": "hello",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Hello from the Time Tracker Backend!",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"securityDefinitions": {
|
|
||||||
"BearerAuth": {
|
|
||||||
"type": "apiKey",
|
|
||||||
"name": "Authorization",
|
|
||||||
"in": "header"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
|
||||||
var SwaggerInfo = &swag.Spec{
|
|
||||||
Version: "1.0",
|
|
||||||
Host: "localhost:8080",
|
|
||||||
BasePath: "/api",
|
|
||||||
Schemes: []string{},
|
|
||||||
Title: "Time Tracker API",
|
|
||||||
Description: "This is a simple time tracker API.",
|
|
||||||
InfoInstanceName: "swagger",
|
|
||||||
SwaggerTemplate: docTemplate,
|
|
||||||
LeftDelim: "{{",
|
|
||||||
RightDelim: "}}",
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"swagger": "2.0",
|
|
||||||
"info": {
|
|
||||||
"description": "This is a simple time tracker API.",
|
|
||||||
"title": "Time Tracker API",
|
|
||||||
"contact": {},
|
|
||||||
"version": "1.0"
|
|
||||||
},
|
|
||||||
"host": "localhost:8080",
|
|
||||||
"basePath": "/api",
|
|
||||||
"paths": {
|
|
||||||
"/": {
|
|
||||||
"get": {
|
|
||||||
"description": "Get a hello message",
|
|
||||||
"produces": [
|
|
||||||
"text/plain"
|
|
||||||
],
|
|
||||||
"summary": "Say hello",
|
|
||||||
"operationId": "hello",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Hello from the Time Tracker Backend!",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"securityDefinitions": {
|
|
||||||
"BearerAuth": {
|
|
||||||
"type": "apiKey",
|
|
||||||
"name": "Authorization",
|
|
||||||
"in": "header"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
basePath: /api
|
|
||||||
host: localhost:8080
|
|
||||||
info:
|
|
||||||
contact: {}
|
|
||||||
description: This is a simple time tracker API.
|
|
||||||
title: Time Tracker API
|
|
||||||
version: "1.0"
|
|
||||||
paths:
|
|
||||||
/:
|
|
||||||
get:
|
|
||||||
description: Get a hello message
|
|
||||||
operationId: hello
|
|
||||||
produces:
|
|
||||||
- text/plain
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Hello from the Time Tracker Backend!
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
summary: Say hello
|
|
||||||
securityDefinitions:
|
|
||||||
BearerAuth:
|
|
||||||
in: header
|
|
||||||
name: Authorization
|
|
||||||
type: apiKey
|
|
||||||
swagger: "2.0"
|
|
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -41,30 +42,26 @@ func helloHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Get database configuration with sensible defaults
|
// Get database configuration from environment variables
|
||||||
dbConfig := models.DefaultDatabaseConfig()
|
dbConfig := models.DatabaseConfig{
|
||||||
|
Host: os.Getenv("DB_HOST"),
|
||||||
// Override with environment variables if provided
|
Port: 5432, // Default PostgreSQL port
|
||||||
if host := os.Getenv("DB_HOST"); host != "" {
|
User: os.Getenv("DB_USER"),
|
||||||
dbConfig.Host = host
|
Password: os.Getenv("DB_PASSWORD"),
|
||||||
|
DBName: os.Getenv("DB_NAME"),
|
||||||
|
SSLMode: os.Getenv("DB_SSLMODE"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse port if provided
|
||||||
if port := os.Getenv("DB_PORT"); port != "" {
|
if port := os.Getenv("DB_PORT"); port != "" {
|
||||||
var portInt int
|
if portInt, err := strconv.Atoi(port); err == nil && portInt > 0 {
|
||||||
if _, err := fmt.Sscanf(port, "%d", &portInt); err == nil && portInt > 0 {
|
|
||||||
dbConfig.Port = portInt
|
dbConfig.Port = portInt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if user := os.Getenv("DB_USER"); user != "" {
|
|
||||||
dbConfig.User = user
|
// Validate required configuration
|
||||||
}
|
if dbConfig.Host == "" || dbConfig.User == "" || dbConfig.Password == "" || dbConfig.DBName == "" {
|
||||||
if password := os.Getenv("DB_PASSWORD"); password != "" {
|
log.Fatal("Missing required database configuration. Please set DB_HOST, DB_USER, DB_PASSWORD, and DB_NAME environment variables")
|
||||||
dbConfig.Password = password
|
|
||||||
}
|
|
||||||
if dbName := os.Getenv("DB_NAME"); dbName != "" {
|
|
||||||
dbConfig.DBName = dbName
|
|
||||||
}
|
|
||||||
if sslMode := os.Getenv("DB_SSLMODE"); sslMode != "" {
|
|
||||||
dbConfig.SSLMode = sslMode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set log level based on environment
|
// Set log level based on environment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user