server: add routes to md
This commit is contained in:
@@ -2,6 +2,8 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -9,8 +11,11 @@ import (
|
|||||||
"git.dubyatp.xyz/dubyatp/scannerbot/server/db"
|
"git.dubyatp.xyz/dubyatp/scannerbot/server/db"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/cors"
|
"github.com/go-chi/cors"
|
||||||
|
"github.com/go-chi/docgen"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var routes = flag.Bool("routes", false, "Generate API route documentation")
|
||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
db.InitPostgres(ctx)
|
db.InitPostgres(ctx)
|
||||||
@@ -88,5 +93,13 @@ func Start() {
|
|||||||
r.Post("/", NewUser)
|
r.Post("/", NewUser)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if *routes {
|
||||||
|
fmt.Println(docgen.MarkdownRoutesDoc(r, docgen.MarkdownOpts{
|
||||||
|
ProjectPath: "git.dubyatp.xyz/williamp/scannerbot",
|
||||||
|
Intro: "ScannerBot Server API routes",
|
||||||
|
}))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
http.ListenAndServe(":3000", r)
|
http.ListenAndServe(":3000", r)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/ajg/form v1.5.1 // indirect
|
github.com/ajg/form v1.5.1 // indirect
|
||||||
github.com/go-chi/cors v1.2.2 // indirect
|
github.com/go-chi/cors v1.2.2 // indirect
|
||||||
|
github.com/go-chi/docgen v1.4.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
|
|||||||
@@ -3,10 +3,14 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-chi/chi/v5 v5.0.1/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||||
github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug=
|
github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug=
|
||||||
github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
|
github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
|
||||||
github.com/go-chi/cors v1.2.2 h1:Jmey33TE+b+rB7fT8MUy1u0I4L+NARQlK6LhzKPSyQE=
|
github.com/go-chi/cors v1.2.2 h1:Jmey33TE+b+rB7fT8MUy1u0I4L+NARQlK6LhzKPSyQE=
|
||||||
github.com/go-chi/cors v1.2.2/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
github.com/go-chi/cors v1.2.2/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||||
|
github.com/go-chi/docgen v1.4.0 h1:0h3Cmw6VGR5WhYUaQA+xVdKVO/WzD/ANiSp5AaPluRQ=
|
||||||
|
github.com/go-chi/docgen v1.4.0/go.mod h1:G9W0G551cs2BFMSn/cnGwX+JBHEloAgo17MBhyrnhPI=
|
||||||
|
github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns=
|
||||||
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
|
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
|
||||||
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||||
@@ -47,6 +51,7 @@ google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zN
|
|||||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ func checkEnvVars(keys []string) (bool, []string) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Debug("No .env file loaded, will try OS environment variables")
|
slog.Debug("No .env file loaded, will try OS environment variables")
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
# git.dubyatp.xyz/williamp/scannerbot
|
||||||
|
|
||||||
|
ScannerBot Server API routes
|
||||||
|
|
||||||
|
## Routes
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>`/`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [Start.func1]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/channels`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/channels**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [ListChannels]()
|
||||||
|
- _POST_
|
||||||
|
- [NewChannel]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/channels/{channelID}`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/channels**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/{channelID}**
|
||||||
|
- **/**
|
||||||
|
- _DELETE_
|
||||||
|
- [DeleteChannel]()
|
||||||
|
- _GET_
|
||||||
|
- [GetChannel]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/channels/{channelID}/messages`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/channels**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/{channelID}**
|
||||||
|
- **/messages**
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [ListMessages]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/channels/{channelID}/messages/{messageID}`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/channels**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/{channelID}**
|
||||||
|
- **/messages**
|
||||||
|
- **/{messageID}**
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [GetMessage]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/files/{fileID}`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/files**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/{fileID}**
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [ServeFile]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/login`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/login**
|
||||||
|
- **/**
|
||||||
|
- _POST_
|
||||||
|
- [Login]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/logout`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/logout**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/**
|
||||||
|
- _POST_
|
||||||
|
- [Logout]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/register`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/register**
|
||||||
|
- **/**
|
||||||
|
- _POST_
|
||||||
|
- [NewUser]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/users`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/users**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [ListUsers]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/users/{userID}`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/users**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- **/{userID}**
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [GetUser]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>`/whoami`</summary>
|
||||||
|
|
||||||
|
- [o-chi/cors.(*Cors).Handler-fm]()
|
||||||
|
- **/whoami**
|
||||||
|
- [SessionAuthMiddleware]()
|
||||||
|
- [LoginCtx]()
|
||||||
|
- **/**
|
||||||
|
- _GET_
|
||||||
|
- [Whoami]()
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
Total # of routes: 12
|
||||||
|
|
||||||
Reference in New Issue
Block a user