Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sash20m committed Nov 17, 2023
0 parents commit bf090a9
Show file tree
Hide file tree
Showing 30 changed files with 1,952 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
48 changes: 48 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
watch_dir = "./"

exclude_dir = ["assets", "tmp", "vendor"]


[build]
args_bin = []
bin = "cmd/server/tmp/main"
cmd = "cd cmd/server && go build -o ./tmp/main ."
delay = 0
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
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/tmp
/*/*/tmp

.env
/logs
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM golang:1.21 AS build

WORKDIR /app

COPY go.mod ./
COPY go.sum ./

RUN go mod download

COPY ./cmd/server/main.go ./cmd/server/main.go
COPY ./cmd/server/docs/ ./cmd/server/docs/
COPY ./pkg/ ./pkg/
COPY ./internal/ ./internal/
COPY ./config/ ./config/

RUN CGO_ENABLED=0 go build -o ./server ./cmd/server/main.go

# Stage 2
FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

COPY --from=0 /app/server ./
COPY ./migrations/ ./migrations/
COPY .env.prod .env.prod
COPY .env .env
COPY ./logs/ ./logs/

EXPOSE 8080

CMD ["./server"]
Binary file added cmd/.DS_Store
Binary file not shown.
Binary file added cmd/server/.DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions cmd/server/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.DEFAULT_GOAL := build

fmt:
go fmt ./...
.PHONY:fmt

lint: fmt
golint ./...
.PHONY:lint

vet: lint
go vet ./...
shadow ./...
.PHONY:vet

swag: vet
swag init -d ./,../../internal
.PHONY: swag

build: swag
go build main.go
.PHONY:build
261 changes: 261 additions & 0 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/book/add": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Books"
],
"summary": "Add a specific book",
"parameters": [
{
"description": "Book title",
"name": "title",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Book author",
"name": "author",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Book coverUrl",
"name": "coverUrl",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Book post url",
"name": "postUrl",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.IDResponse"
}
}
}
}
},
"/api/book/delete/{id}": {
"delete": {
"produces": [
"application/json"
],
"tags": [
"Books"
],
"summary": "Delete a specific book",
"parameters": [
{
"type": "integer",
"description": "Book ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.GetBookResponse"
}
}
}
}
},
"/api/book/update": {
"patch": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Books"
],
"summary": "Update a specific book",
"parameters": [
{
"description": "Book title",
"name": "title",
"in": "body",
"schema": {
"type": "string"
}
},
{
"description": "Book author",
"name": "author",
"in": "body",
"schema": {
"type": "string"
}
},
{
"description": "Book coverUrl",
"name": "coverUrl",
"in": "body",
"schema": {
"type": "string"
}
},
{
"description": "Book post url",
"name": "postUrl",
"in": "body",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.IDResponse"
}
}
}
}
},
"/api/book/{id}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Books"
],
"summary": "Get a specific book",
"parameters": [
{
"type": "integer",
"description": "Book ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.GetBookResponse"
}
}
}
}
},
"/api/books": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Books"
],
"summary": "Get all books",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/model.GetBookResponse"
}
}
}
}
}
}
},
"definitions": {
"model.GetBookResponse": {
"type": "object",
"properties": {
"author": {
"type": "string"
},
"coverUrl": {
"type": "string"
},
"id": {
"type": "integer"
},
"postUrl": {
"type": "string"
},
"title": {
"type": "string"
}
}
},
"model.IDResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "Go Rest Api",
Description: "Api Endpoints for Go Server",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
Loading

0 comments on commit bf090a9

Please sign in to comment.