Skip to content

Commit

Permalink
Add new web
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed Oct 3, 2023
1 parent 7bea63e commit 07f3139
Show file tree
Hide file tree
Showing 31 changed files with 2,518 additions and 54 deletions.
1 change: 1 addition & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ FROM centos:7
WORKDIR /app

COPY --from=build /app/openapi /app/openapi
COPY --from=build /app/public /app/public

VOLUME /tmp

Expand Down
42 changes: 27 additions & 15 deletions web/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,50 @@ package main

import (
"fmt"
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
echoSwagger "github.com/swaggo/echo-swagger"
"github.com/yoda/web/internal/api"
"github.com/yoda/web/internal/config"
stock "github.com/yoda/web/internal/controller"
"github.com/yoda/web/internal/controller"
_ "github.com/yoda/web/internal/docs"
"github.com/yoda/web/internal/middleware"
"github.com/yoda/web/internal/service"
"github.com/yoda/web/internal/service/auth"
"github.com/yoda/web/internal/service/sale"
"github.com/yoda/web/internal/storage"
"strings"
"os"
)

// @BasePath /rest
// @Host petstore.swagger.io
// @title Swagger Example API
func main() {
config := config.LoadConfig("config.yml")
store := storage.NewStorage(config.Database)
srv := stock.NewServer(store)

orderService := service.NewOrderService(store)
saleService := sale.NewSaleService(store)
authService := auth.NewAuthService(store)

controller := controller.NewController(store, orderService, saleService, authService)

e := echo.New()
e.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{
Skipper: func(c echo.Context) bool {
return strings.Contains(c.Path(), "/swagger") || strings.Contains(c.Path(), "/api")
},
KeyLookup: "header:X-API-KEY",
Validator: func(key string, c echo.Context) (bool, error) {
return key == "9609c3c0-2026-11ee-be56-0242ac120002", nil
},
}))
e.Use(middleware.JWTValidationMiddleware(authService))

e.Debug = true

api.RegisterHandlers(e, srv)
api.RegisterHandlersWithBaseURL(e, controller, "/rest")

e.Static("/api", "openapi")
e.GET("/swagger/*", echoSwagger.EchoWrapHandler(echoSwagger.URL("/api/openapi.yml")))
e.Static("/api", "openapi")
e.Static("/", "public")

e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", config.Port)))
}

func initSessionMiddleware(e *echo.Echo) {
var sessionStore = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))
e.Use(session.Middleware(sessionStore))
}
62 changes: 53 additions & 9 deletions web/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,38 @@ module github.com/yoda/web
go 1.20

require (
github.com/deepmap/oapi-codegen v1.13.0
github.com/deepmap/oapi-codegen v1.14.0
github.com/fatih/structs v1.1.0
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/gorilla/sessions v1.2.1
github.com/knadh/koanf/parsers/yaml v0.1.0
github.com/knadh/koanf/providers/confmap v0.1.0
github.com/knadh/koanf/providers/file v0.1.0
github.com/knadh/koanf/v2 v2.0.1
github.com/labstack/echo/v4 v4.10.2
github.com/labstack/echo-contrib v0.15.0
github.com/labstack/echo/v4 v4.11.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/swaggo/echo-swagger v1.4.0
github.com/swaggo/swag v1.16.1
github.com/xuri/excelize/v2 v2.8.0
gorm.io/driver/postgres v1.5.2
gorm.io/gorm v1.25.2
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet/v6 v6.2.0 // indirect
github.com/Joker/jade v1.1.3 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/flosch/pongo2/v4 v4.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand All @@ -34,40 +48,70 @@ require (
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomarkdown/markdown v0.0.0-20230716120725-531d2d74bc12 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/iris-contrib/schema v0.0.6 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kataras/blocks v0.0.7 // indirect
github.com/kataras/golog v0.1.9 // indirect
github.com/kataras/iris/v12 v12.2.5 // indirect
github.com/kataras/pio v0.0.12 // indirect
github.com/kataras/sitemap v0.0.6 // indirect
github.com/kataras/tunnel v0.0.4 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/labstack/echo-jwt/v4 v4.2.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/tdewolff/minify/v2 v2.12.8 // indirect
github.com/tdewolff/parse/v2 v2.6.7 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca // indirect
github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a // indirect
github.com/yosssi/ace v0.0.5 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 07f3139

Please sign in to comment.