Compare commits

...

5 Commits

10 changed files with 162 additions and 7 deletions

46
.air.linux.toml Normal file
View File

@ -0,0 +1,46 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "tmp\\main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
keep_scroll = true

View File

@ -1,3 +1,3 @@
tmp
docker-compose.yaml
.air.toml
.air*.toml

18
.woodpecker/build.yml Normal file
View File

@ -0,0 +1,18 @@
steps:
- name: build latest
image: woodpeckerci/plugin-docker-buildx
settings:
repo: registry.odit.services/lfk/document-server
tags:
- latest
registry: registry.odit.services
platforms: linux/amd64,linux/arm64
cache_from: registry.odit.services/lfk/document-server:latest
username:
from_secret: odit-registry-builder-username
password:
from_secret: odit-registry-builder-password
when:
branch: main
when:
event: push

17
.woodpecker/release.yml Normal file
View File

@ -0,0 +1,17 @@
steps:
- name: build tag
image: woodpeckerci/plugin-docker-buildx
settings:
repo: registry.odit.services/lfk/document-server
tags:
- "${CI_COMMIT_TAG}"
registry: registry.odit.services
platforms: linux/amd64,linux/arm64
cache_from: registry.odit.services/lfk/document-server:latest
username:
from_secret: odit-registry-builder-username
password:
from_secret: odit-registry-builder-password
when:
event:
- tag

View File

@ -2,7 +2,7 @@
## Features
- 📝 HTML pdf templates
- 📝 HTML templates for pdf generation
- 📚 OpenAPI/Swagger documentation
- ⚡ High-performance with go and gotenberg
@ -12,9 +12,6 @@
# Install dependencies
go mod download
# Generate the swagger docs
swag init
# Run the server
air
```
@ -29,3 +26,45 @@ The project uses:
- 🏃‍♂️ go as the language and build tool
- 🌐 gofiber for the web framework
- 📦 air for live reload
- 📝 swaggo for API documentation
- 📄 gotenberg for HTML to PDF conversion
### 📦 Use docker compose for external dependencies
```shell
docker compose -f docker-compose.dev.yaml up
```
### 🏃 Run via air
> Install air via `go install github.com/air-verse/air@latest`
```shell
# With the default air config
air
# With the config for linux/macOS
air -c .air.linux.toml
# With the config for windows
air -c .air.windows.toml
```
### ✒️ Update the swagger docs
> Install swag via `go install github.com/swaggo/swag/cmd/swag@latest`
```shell
swag init
```
### 🐋 Build container
```shell
# single arch
docker build -t registry.odit.services/lfk/document-server:latest .
# multiarch
docker buildx build --platform=linux/amd64,linux/arm64 -t registry.odit.services/lfk/document-server:latest --push .
```

View File

@ -320,7 +320,19 @@ const docTemplate = `{
}
}
}
}
},
"securityDefinitions": {
"ApiKeyAuth": {
"type": "apiKey",
"name": "key",
"in": "query"
}
},
"security": [
{
"ApiKeyAuth": []
}
]
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it

View File

@ -311,5 +311,17 @@
}
}
}
}
},
"securityDefinitions": {
"ApiKeyAuth": {
"type": "apiKey",
"name": "key",
"in": "query"
}
},
"security": [
{
"ApiKeyAuth": []
}
]
}

View File

@ -211,4 +211,11 @@ paths:
summary: Generate a contract
tags:
- contracts
security:
- ApiKeyAuth: []
securityDefinitions:
ApiKeyAuth:
in: query
name: key
type: apiKey
swagger: "2.0"

View File

@ -57,6 +57,9 @@ func loadEnv() error {
// @title LfK Document Server API
// @description This is the API documentation for the LfK Document Server - a tool for pdf generation.
// @securityDefinitions.apiKey ApiKeyAuth
// @in query
// @name key
func main() {
err := loadEnv()
@ -76,6 +79,7 @@ func main() {
// Swagger documentation route
app.Get("/swagger/*", swagger.HandlerDefault)
// @Security ApiKeyAuth
v1 := app.Group("/v1")
v1.Use(keyauth.New(keyauth.Config{
KeyLookup: "query:key",