Feature/dynamic swagger uri (#15)

* made the swagger uri based on env

* updated swagger to reflect the dynamic uri

* updated extamples
This commit is contained in:
James Tombleson 2022-07-14 09:59:55 -07:00 committed by GitHub
parent f01a8ff592
commit 79f3383fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 10 deletions

View File

@ -15,6 +15,7 @@ This is the collection service of newsbot to pull articles from the web.
2. `curl -X 'GET' 'http://localhost:8081/api/config/sources' -H 'accept: application/json'` 2. `curl -X 'GET' 'http://localhost:8081/api/config/sources' -H 'accept: application/json'`
6. Add any new sources 6. Add any new sources
7. Add a Discord Web Hook 7. Add a Discord Web Hook
1. `curl -X 'POST' 'http://localhost:8081/api/discord/webhooks/new?url=WEBHOOKURL&server=SERVERNAME&channel=CHANNELNAME' -H 'accept: application/json' -d ''`
8. Create your subscription links 8. Create your subscription links
1. This is a link between a source and a discord web hook. Without this, the app will not send a notification about new posts. 1. This is a link between a source and a discord web hook. Without this, the app will not send a notification about new posts.

View File

@ -7,6 +7,8 @@ services:
api: api:
image: ghcr.io/jtom38/newsbot.collector.api:master image: ghcr.io/jtom38/newsbot.collector.api:master
environment: environment:
SERVER_ADDRESS: "localhost"
SQL_CONNECTION_STRING: "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" SQL_CONNECTION_STRING: "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable"
# Used for database migrations # Used for database migrations
@ -21,6 +23,7 @@ services:
# Enable/Disable YouTube monitoring # Enable/Disable YouTube monitoring
FEATURE_ENABLE_YOUTUBE_BACKEND: false FEATURE_ENABLE_YOUTUBE_BACKEND: false
FEATURE_ENABLE_TWITCH_BACKEND: false
# Set your Twitch Developer ID and Secrets here and they will be used to collect updates. # Set your Twitch Developer ID and Secrets here and they will be used to collect updates.
TWITCH_CLIENT_ID: "" TWITCH_CLIENT_ID: ""
TWITCH_CLIENT_SECRET: "" TWITCH_CLIENT_SECRET: ""

View File

@ -518,7 +518,7 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "0.1", Version: "0.1",
Host: "localhost:8081", Host: "",
BasePath: "/api", BasePath: "/api",
Schemes: []string{}, Schemes: []string{},
Title: "NewsBot collector", Title: "NewsBot collector",

View File

@ -5,7 +5,6 @@
"contact": {}, "contact": {},
"version": "0.1" "version": "0.1"
}, },
"host": "localhost:8081",
"basePath": "/api", "basePath": "/api",
"paths": { "paths": {
"/articles": { "/articles": {

View File

@ -1,5 +1,4 @@
basePath: /api basePath: /api
host: localhost:8081
info: info:
contact: {} contact: {}
title: NewsBot collector title: NewsBot collector

13
main.go
View File

@ -5,16 +5,20 @@ import (
"fmt" "fmt"
"net/http" "net/http"
_ "github.com/jtom38/newsbot/collector/docs" "github.com/jtom38/newsbot/collector/docs"
"github.com/jtom38/newsbot/collector/routes" "github.com/jtom38/newsbot/collector/routes"
"github.com/jtom38/newsbot/collector/services/config"
"github.com/jtom38/newsbot/collector/services/cron" "github.com/jtom38/newsbot/collector/services/cron"
) )
// @title NewsBot collector // @title NewsBot collector
// @version 0.1 // @version 0.1
// @BasePath /api // @BasePath /api
func main() { func main() {
cfg := config.New()
address := cfg.GetConfig(config.ServerAddress)
docs.SwaggerInfo.Host = fmt.Sprintf("%v:8081", address)
ctx := context.Background() ctx := context.Background()
c := cron.New(ctx) c := cron.New(ctx)
c.Start() c.Start()
@ -22,8 +26,9 @@ func main() {
server := routes.NewServer(ctx) server := routes.NewServer(ctx)
fmt.Println("API is online and waiting for requests.") fmt.Println("API is online and waiting for requests.")
fmt.Println("API: http://localhost:8081/api") fmt.Printf("API: http://%v:8081/api\r\n", address)
fmt.Println("Swagger: http://localhost:8081/swagger/index.html") fmt.Printf("Swagger: http://%v:8081/swagger/index.html\r\n", address)
err := http.ListenAndServe(":8081", server.Router) err := http.ListenAndServe(":8081", server.Router)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -11,9 +11,9 @@ import (
) )
const ( const (
DB_URI string = "DB_URI" ServerAddress = "SERVER_ADDRESS"
Sql_Connection_String string = "SQL_CONNECTION_STRING" Sql_Connection_String = "SQL_CONNECTION_STRING"
FEATURE_ENABLE_REDDIT_BACKEND = "FEATURE_ENABLE_REDDIT_BACKEND" FEATURE_ENABLE_REDDIT_BACKEND = "FEATURE_ENABLE_REDDIT_BACKEND"
REDDIT_PULL_TOP = "REDDIT_PULL_TOP" REDDIT_PULL_TOP = "REDDIT_PULL_TOP"