feat(go-swagger): Refactoring to use go-swagger templating system for most of the work
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Matthieu 'JP' DERASSE
2023-01-01 16:59:41 +00:00
parent d997c0035d
commit 65add2a61d
29 changed files with 538 additions and 21 deletions

View File

@ -0,0 +1,25 @@
# Code generated by gouick; DO NOT EDIT.
FROM alpine
LABEL maintainer="{{.Config.ProjectContact.Name}} <{{.Config.ProjectContact.Email}}>"
RUN apk add --no-cache ca-certificates
USER nobody
COPY launcher.sh \
{{- range .APIs }}
{{.Binary}} \
{{- end }}
{{- range .Crons }}
{{.Binary}} \
{{- end }}
{{- range .Workers }}
{{.Binary}} \
{{- end }}
/app/
# expose port 8080
EXPOSE 8080
CMD [ "/app/launcher.sh" ]

View File

@ -0,0 +1,49 @@
# Code generated by gouick; DO NOT EDIT.
{{ if eq (len .APIs) 1 }}
api:
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@echo "\tLaunch API '{{ (index .APIs 0).Binary }}'"
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \
go run cmd/{{ (index .APIs 0).Binary }}/*
{{ else if gt (len .APIs) 1 }}
{{- range .APIs -}}
{{.Binary}}
{{ end }}:
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@echo "\tLaunch API '$@'"
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \
go run cmd/$@/main.go
{{ end }}
{{- if ne (len .Workers) 0 }}
{{- range .Workers -}}
{{.Binary}}
{{ end }}:
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@echo "\tLaunch worker '$@'"
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \
go run cmd/$@/main.go
{{ end }}
{{- if ne (len .Crons) 0 }}
{{- range .Crons -}}
{{.Binary}}
{{ end }}:
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@echo "\tLaunch cron '$@'"
@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
@PORT=${PORT:-3000} HOST=${HOST:-0.0.0.0} \
go run cmd/$@/main.go
{{ end }}
generate:
@gouick generate
test:
@gouick test
.PHONY: api generate test

View File

@ -0,0 +1,17 @@
# {{ .Config.ProjectName }}
{{ .Config.ProjectDescription }}
## Table of Contents
* [Technologies Used](#technologies-used)
* [Contact](#contact)
## Technologies Used
- [Gouick](https://git.dev.m-and-m.ovh/mderasse/gouick): Toolbox to quickly generate a API using Go-Swagger.
## Contact
Created by [{{ .Config.ProjectContact.Name }}](mailto:{{ .Config.ProjectContact.Email }})
{{- if .Config.ProjectContact.URL }}
**Website:** "{{ .Config.ProjectContact.URL }}"
{{- end }}

View File

@ -0,0 +1,17 @@
---
swagger: "2.0"
info:
version: "1.0"
title: "{{ .Config.ProjectName }}"
description: "{{ .Config.ProjectDescription }}"
contact:
name: "{{ .Config.ProjectContact.Name }}"
email: "{{ .Config.ProjectContact.Email }}"
{{- if .Config.ProjectContact.URL }}
url: "{{ .Config.ProjectContact.URL }}"
{{- end }}
consumes:
- "application/json"
produces:
- "application/json"
basePath: "/"

View File

@ -0,0 +1,25 @@
---
definitions:
#
# GENERAL TYPEs
#
Error:
type: object
properties:
code:
type: integer
format: int64
message:
type: string
Metadata:
type: object
required:
- this
- total
properties:
total:
type: integer
format: int64
this:
type: integer
format: int64

View File

@ -0,0 +1,48 @@
---
tags:
- name: Monitoring
description: Monitoring routes
definitions:
MonPing:
type: object
properties:
status:
type: object
x-nullable: true
properties:
database:
type: boolean
description: State of the database
application:
type: boolean
description: State of the application
details:
type: object
x-nullable: true
properties:
app_version:
type: string
description: Application version
git_hash:
type: string
description: Git hash of the last commit
paths:
#
# SECTION : MONITORING
#
/unsecured/mon/ping:
get:
tags:
- Monitoring
summary: Health check
description: Return Health status of the app with additionnal info such as the version
operationId: getMonPing
responses:
200:
description: Health OK
schema:
$ref: "#/definitions/MonPing"
default:
description: Default error message
schema:
$ref: "#/definitions/Error"

View File

@ -0,0 +1,62 @@
#!/bin/sh
# Code generated by gouick; DO NOT EDIT.
# the launcher file will launch the correct app / worker based on the given env variable
# the main goal of that launcher is to be used as a Docker entrypoint
# APP_TYPE: Can be api, worker or cron
case "$APP_TYPE" in
{{ if eq (len .APIs) 1 }}
# API
api) exec /app/{{ (index .APIs 0).Binary }} ;;
{{ else if gt (len .APIs) 1 }}
{{range .APIs}}
# API {{.Name}}
{{.Name}}) exec /app/{{.Binary}} ;;
{{end}}
{{end}}
{{- if ne (len .Workers) 0 }}
# Workers
worker)
case "$WORKER_NAME" in
{{range .Workers}}
# Worker {{.Name}}
{{.Name}}) exec /app/{{.Binary}} ;;
{{end}}
# otherwise
*)
echo "** invalid WORKER_NAME='$WORKER_NAME'. Please use a valid worker name!"
exit 1
;;
esac
;;
{{end}}
{{- if ne (len .Crons) 0 }}
# Crons
cron)
case "$CRON_NAME" in
{{range .Crons}}
# Cron {{.Name}}
{{.Name}}) exec /app/{{.Binary}} ;;
{{end}}
# otherwise
*)
echo "** invalid CRON_NAME='$CRON_NAME'. Please use a valid cron name!"
exit 1
;;
esac
;;
{{end}}
# otherwise
*)
echo "** invalid APP_TYPE='$APP_TYPE' ! Please use API, WORKER or CRON!"
exit 1
;;
esac