Loads of updates

This commit is contained in:
2021-06-22 22:52:48 +02:00
parent 8dc20a4eb0
commit ccafd60923
18 changed files with 1206 additions and 125 deletions

366
src/docs/docs.go Normal file
View File

@@ -0,0 +1,366 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag
package docs
import (
"bytes"
"encoding/json"
"strings"
"github.com/alecthomas/template"
"github.com/swaggo/swag"
)
var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
"title": "{{.Title}}",
"contact": {
"name": "Power Plan",
"url": "https://http://pwrpln.com/",
"email": "lilleman@larvit.se"
},
"license": {
"name": "MIT"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/account": {
"post": {
"description": "Create an account",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Create an account",
"operationId": "account-create",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.CreatedAccount"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/account/{id}": {
"get": {
"description": "Get account",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Get account",
"operationId": "get-account-by-id",
"parameters": [
{
"type": "string",
"description": "Account ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/auth/api-key": {
"post": {
"description": "Authenticate account by API Key",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Authenticate account by API Key",
"operationId": "auth-account-by-api-key",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/auth/password": {
"post": {
"description": "Authenticate account by Password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Authenticate account by Password",
"operationId": "auth-account-by-password",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/renew-token": {
"post": {
"description": "Renew token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Renew token",
"operationId": "renew-token",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
}
},
"definitions": {
"db.Account": {
"type": "object",
"properties": {
"created": {
"type": "string"
},
"fields": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"db.CreatedAccount": {
"type": "object",
"properties": {
"apiKey": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"handlers.ResJSONError": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"field": {
"type": "string"
}
}
}
}
}`
type swaggerInfo struct {
Version string
Host string
BasePath string
Schemes []string
Title string
Description string
}
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = swaggerInfo{
Version: "0.1",
Host: "localhost:3000",
BasePath: "/",
Schemes: []string{},
Title: "JWT Auth API",
Description: "This is a tiny http API for auth. Register accounts, auth with api-key or name/password, renew JWT tokens...",
}
type s struct{}
func (s *s) ReadDoc() string {
sInfo := SwaggerInfo
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
t, err := template.New("swagger_info").Funcs(template.FuncMap{
"marshal": func(v interface{}) string {
a, _ := json.Marshal(v)
return string(a)
},
}).Parse(doc)
if err != nil {
return doc
}
var tpl bytes.Buffer
if err := t.Execute(&tpl, sInfo); err != nil {
return doc
}
return tpl.String()
}
func init() {
swag.Register(swag.Name, &s{})
}

304
src/docs/swagger.json Normal file
View File

@@ -0,0 +1,304 @@
{
"swagger": "2.0",
"info": {
"description": "This is a tiny http API for auth. Register accounts, auth with api-key or name/password, renew JWT tokens...",
"title": "JWT Auth API",
"contact": {
"name": "Power Plan",
"url": "https://http://pwrpln.com/",
"email": "lilleman@larvit.se"
},
"license": {
"name": "MIT"
},
"version": "0.1"
},
"host": "localhost:3000",
"basePath": "/",
"paths": {
"/account": {
"post": {
"description": "Create an account",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Create an account",
"operationId": "account-create",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.CreatedAccount"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/account/{id}": {
"get": {
"description": "Get account",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Get account",
"operationId": "get-account-by-id",
"parameters": [
{
"type": "string",
"description": "Account ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/auth/api-key": {
"post": {
"description": "Authenticate account by API Key",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Authenticate account by API Key",
"operationId": "auth-account-by-api-key",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/auth/password": {
"post": {
"description": "Authenticate account by Password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Authenticate account by Password",
"operationId": "auth-account-by-password",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
},
"/renew-token": {
"post": {
"description": "Renew token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Renew token",
"operationId": "renew-token",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
}
},
"definitions": {
"db.Account": {
"type": "object",
"properties": {
"created": {
"type": "string"
},
"fields": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"db.CreatedAccount": {
"type": "object",
"properties": {
"apiKey": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"handlers.ResJSONError": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"field": {
"type": "string"
}
}
}
}
}

203
src/docs/swagger.yaml Normal file
View File

@@ -0,0 +1,203 @@
basePath: /
definitions:
db.Account:
properties:
created:
type: string
fields:
additionalProperties:
items:
type: string
type: array
type: object
id:
type: string
name:
type: string
type: object
db.CreatedAccount:
properties:
apiKey:
type: string
id:
type: string
name:
type: string
type: object
handlers.ResJSONError:
properties:
error:
type: string
field:
type: string
type: object
host: localhost:3000
info:
contact:
email: lilleman@larvit.se
name: Power Plan
url: https://http://pwrpln.com/
description: This is a tiny http API for auth. Register accounts, auth with api-key
or name/password, renew JWT tokens...
license:
name: MIT
title: JWT Auth API
version: "0.1"
paths:
/account:
post:
consumes:
- application/json
description: Create an account
operationId: account-create
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/db.CreatedAccount'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/handlers.ResJSONError'
"403":
description: Forbidden
schema:
$ref: '#/definitions/handlers.ResJSONError'
"415":
description: Unsupported Media Type
schema:
$ref: '#/definitions/handlers.ResJSONError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ResJSONError'
summary: Create an account
/account/{id}:
get:
consumes:
- application/json
description: Get account
operationId: get-account-by-id
parameters:
- description: Account ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/db.Account'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/handlers.ResJSONError'
"403":
description: Forbidden
schema:
$ref: '#/definitions/handlers.ResJSONError'
"415":
description: Unsupported Media Type
schema:
$ref: '#/definitions/handlers.ResJSONError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ResJSONError'
summary: Get account
/auth/api-key:
post:
consumes:
- application/json
description: Authenticate account by API Key
operationId: auth-account-by-api-key
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/db.Account'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/handlers.ResJSONError'
"403":
description: Forbidden
schema:
$ref: '#/definitions/handlers.ResJSONError'
"415":
description: Unsupported Media Type
schema:
$ref: '#/definitions/handlers.ResJSONError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ResJSONError'
summary: Authenticate account by API Key
/auth/password:
post:
consumes:
- application/json
description: Authenticate account by Password
operationId: auth-account-by-password
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/db.Account'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/handlers.ResJSONError'
"403":
description: Forbidden
schema:
$ref: '#/definitions/handlers.ResJSONError'
"415":
description: Unsupported Media Type
schema:
$ref: '#/definitions/handlers.ResJSONError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ResJSONError'
summary: Authenticate account by Password
/renew-token:
post:
consumes:
- application/json
description: Renew token
operationId: renew-token
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/db.Account'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/handlers.ResJSONError'
"403":
description: Forbidden
schema:
$ref: '#/definitions/handlers.ResJSONError'
"415":
description: Unsupported Media Type
schema:
$ref: '#/definitions/handlers.ResJSONError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ResJSONError'
summary: Renew token
swagger: "2.0"