Skip to content

Commit

Permalink
drop statik
Browse files Browse the repository at this point in the history
  • Loading branch information
aradwann committed Jan 4, 2024
1 parent 6bd5fb5 commit 8474093
Show file tree
Hide file tree
Showing 13 changed files with 536 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# Go workspace file
go.work

eenergy
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ server:
go run main.go

protoc:
rm -f pb/*.go
rm -f doc/swagger/*.swagger.json
protoc --proto_path=proto --go_out=pb --go_opt=paths=source_relative \
--go-grpc_out=pb --go-grpc_opt=paths=source_relative \
--grpc-gateway_out=pb --grpc-gateway_opt paths=source_relative \
--go-grpc_out=pb --go-grpc_opt=paths=source_relative \
--grpc-gateway_out=pb --grpc-gateway_opt=paths=source_relative \
--openapiv2_out=doc/swagger --openapiv2_opt=allow_merge=true,merge_file_name=eenergy \
proto/*.proto
statik -f -src=./doc/swagger -dest=./doc
proto/*.proto

evans:
evans --host localhost --port 9090 -r repl
Expand Down
14 changes: 0 additions & 14 deletions doc/statik/statik.go

This file was deleted.

63 changes: 63 additions & 0 deletions doc/swagger/eenergy.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"paths": {
"/v1/create_user": {
"post": {
"summary": "Create new user",
"description": "Use this API to create a new user",
"operationId": "EenergyService_CreateUser",
"responses": {
"200": {
Expand Down Expand Up @@ -55,6 +57,8 @@
},
"/v1/login_user": {
"post": {
"summary": "Login user",
"description": "Use this API to login user and get access token \u0026 refresh token",
"operationId": "EenergyService_LoginUser",
"responses": {
"200": {
Expand Down Expand Up @@ -84,6 +88,40 @@
"EenergyService"
]
}
},
"/v1/update_user": {
"patch": {
"summary": "Update user",
"description": "Use this API to update user",
"operationId": "EenergyService_UpdateUser",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/pbUpdateUserResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/pbUpdateUserRequest"
}
}
],
"tags": [
"EenergyService"
]
}
}
},
"definitions": {
Expand Down Expand Up @@ -148,6 +186,31 @@
}
}
},
"pbUpdateUserRequest": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"fullName": {
"type": "string"
},
"email": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"pbUpdateUserResponse": {
"type": "object",
"properties": {
"user": {
"$ref": "#/definitions/pbUser"
}
}
},
"pbUser": {
"type": "object",
"properties": {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0
github.com/jackc/pgx/v5 v5.5.1
github.com/o1egl/paseto v1.0.0
github.com/rakyll/statik v0.1.7
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
go.uber.org/mock v0.4.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
Expand Down
16 changes: 7 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ package main
import (
"context"
"database/sql"
"embed"
"fmt"
"log"
"net"
"net/http"
"os"

db "github.com/aradwann/eenergy/db/store"
_ "github.com/aradwann/eenergy/doc/statik"
"github.com/aradwann/eenergy/gapi"
"github.com/aradwann/eenergy/pb"
"github.com/aradwann/eenergy/util"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/rakyll/statik/fs"

"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/encoding/protojson"
)

//go:embed doc/swagger/*
var content embed.FS

func main() {
config, err := util.LoadConfig(".", "app")
if err != nil {
Expand Down Expand Up @@ -95,14 +97,10 @@ func runGatewayServer(config util.Config, store db.Store) {
}

mux := http.NewServeMux()
// Handle gRPC requests
mux.Handle("/", grpcMux)

statikFs, err := fs.New()
if err != nil {
log.Fatalf("cannot create statik fs: %s", err)
}
swaggerHandler := http.StripPrefix("/swagger/", http.FileServer(statikFs))
mux.Handle("/swagger/", swaggerHandler)
// TODO: fix serving URL
mux.Handle("/swagger/", http.FileServer(http.FS(content)))

listener, err := net.Listen("tcp", config.HTTPServerAddress)
if err != nil {
Expand Down
Loading

0 comments on commit 8474093

Please sign in to comment.