generate with blueprint
This commit is contained in:
parent
8cc929ffb5
commit
01ac5d4bf3
161
.gitignore
vendored
Normal file
161
.gitignore
vendored
Normal file
@ -0,0 +1,161 @@
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,goland,go
|
||||
|
||||
### Go ###
|
||||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
|
||||
### GoLand ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
.idea
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### GoLand Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator-enh.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
.idea/codestream.xml
|
||||
|
||||
# Azure Toolkit for IntelliJ plugin
|
||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||
.idea/**/azureSettings.xml
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go
|
20
blueprint.yaml
Normal file
20
blueprint.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
templateProjectName: amocrm
|
||||
Description: Service for integration with amocrm
|
||||
|
||||
Template:
|
||||
path: "./"
|
||||
|
||||
Modules:
|
||||
logger:
|
||||
name: zap
|
||||
env:
|
||||
vars:
|
||||
- name: APP_NAME
|
||||
type: string
|
||||
default: "{{.ProjectName}}"
|
||||
openapi:
|
||||
model_save_path: ./internal/models
|
||||
controller_save_path: ./internal/controllers
|
||||
service_save_path: ./internal/service
|
||||
repository_save_path: ./internal/repository
|
||||
server_save_path: ./internal/server/http
|
38
cmd/main.go
Normal file
38
cmd/main.go
Normal file
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"amocrm/internal/app"
|
||||
"context"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/caarlos0/env/v8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfgLogger := zap.NewDevelopmentConfig()
|
||||
cfgLogger.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
||||
cfgLogger.EncoderConfig.ConsoleSeparator = " "
|
||||
|
||||
logger, err := cfgLogger.Build()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
var config app.Config
|
||||
|
||||
err = env.Parse(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := app.Run(ctx, config, logger); err != nil {
|
||||
logger.Fatal("Failed to run app", zap.Any("Error", err))
|
||||
}
|
||||
}
|
4
database.puml
Normal file
4
database.puml
Normal file
@ -0,0 +1,4 @@
|
||||
@startuml Database
|
||||
|
||||
|
||||
@enduml
|
24
go.mod
Normal file
24
go.mod
Normal file
@ -0,0 +1,24 @@
|
||||
module amocrm
|
||||
|
||||
go 1.21.6
|
||||
|
||||
require (
|
||||
github.com/caarlos0/env/v8 v8.0.0
|
||||
github.com/gofiber/fiber/v2 v2.52.4
|
||||
go.uber.org/zap v1.27.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/google/uuid v1.5.0 // indirect
|
||||
github.com/klauspost/compress v1.17.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.51.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
)
|
43
go.sum
Normal file
43
go.sum
Normal file
@ -0,0 +1,43 @@
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0=
|
||||
github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
|
||||
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
|
||||
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
|
||||
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
76
internal/app/app.go
Normal file
76
internal/app/app.go
Normal file
@ -0,0 +1,76 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"amocrm/internal/controllers"
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/internal/server/http"
|
||||
"amocrm/internal/service"
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppName string `env:"APP_NAME"`
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, config Config, logger *zap.Logger) error {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Error("Recovered from a panic", zap.Any("error", r))
|
||||
}
|
||||
}()
|
||||
|
||||
logger.Info("App started", zap.Any("config", config))
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// Инициализация репозиториев
|
||||
|
||||
accountRepository := repository.NewAccountRepository()
|
||||
|
||||
differentRepository := repository.NewDifferentRepository()
|
||||
|
||||
// Инициализация сервисов
|
||||
|
||||
accountService := service.NewAccountService(accountRepository)
|
||||
|
||||
differentService := service.NewDifferentService(differentRepository)
|
||||
|
||||
// Инициализация контроллеров
|
||||
|
||||
accountController := controllers.NewAccountController(accountService)
|
||||
|
||||
differentController := controllers.NewDifferentController(differentService)
|
||||
|
||||
// Создание сервера
|
||||
server := http.NewServer(http.ServerConfig{
|
||||
Controllers: []http.Controller{
|
||||
|
||||
accountController,
|
||||
|
||||
differentController,
|
||||
},
|
||||
})
|
||||
|
||||
go func() {
|
||||
err := server.Start("Host + : + Port")
|
||||
if err != nil {
|
||||
logger.Error("Server startup error", zap.Error(err))
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
|
||||
// Вывод маршрутов
|
||||
server.ListRoutes()
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
logger.Info("App shutting down gracefully")
|
||||
|
||||
//TODO
|
||||
// Остановка сервера
|
||||
|
||||
return nil
|
||||
}
|
95
internal/controllers/account.go
Normal file
95
internal/controllers/account.go
Normal file
@ -0,0 +1,95 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/service"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type AccountController struct {
|
||||
AccountService *service.AccountService
|
||||
}
|
||||
|
||||
func NewAccountController(service *service.AccountService) *AccountController {
|
||||
return &AccountController{
|
||||
AccountService: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *AccountController) Register(router fiber.Router) {
|
||||
|
||||
router.Get("/users", c.Getlistusers)
|
||||
|
||||
router.Patch("/users", c.Updatelistusers)
|
||||
|
||||
router.Delete("/account", c.Softdeleteaccount)
|
||||
|
||||
router.Get("/account", c.Getcurrentaccount)
|
||||
|
||||
router.Post("/account", c.Connectaccount)
|
||||
|
||||
}
|
||||
|
||||
func (c *AccountController) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *AccountController) Getlistusers(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Getlistusers
|
||||
|
||||
err := c.AccountService.Getlistusers(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *AccountController) Updatelistusers(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Updatelistusers
|
||||
|
||||
err := c.AccountService.Updatelistusers(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *AccountController) Softdeleteaccount(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Softdeleteaccount
|
||||
|
||||
err := c.AccountService.Softdeleteaccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *AccountController) Getcurrentaccount(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Getcurrentaccount
|
||||
|
||||
response, err := c.AccountService.Getcurrentaccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
|
||||
}
|
||||
|
||||
func (c *AccountController) Connectaccount(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Connectaccount
|
||||
|
||||
response, err := c.AccountService.Connectaccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
|
||||
}
|
165
internal/controllers/different.go
Normal file
165
internal/controllers/different.go
Normal file
@ -0,0 +1,165 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/service"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type DifferentController struct {
|
||||
DifferentService *service.DifferentService
|
||||
}
|
||||
|
||||
func NewDifferentController(service *service.DifferentService) *DifferentController {
|
||||
return &DifferentController{
|
||||
DifferentService: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DifferentController) Register(router fiber.Router) {
|
||||
|
||||
router.Get("/tags", c.Getlisttags)
|
||||
|
||||
router.Patch("/tags", c.Updatelisttags)
|
||||
|
||||
router.Get("/webhook/create", c.Webhookcreate)
|
||||
|
||||
router.Get("/webhook/delete", c.Webhookdelete)
|
||||
|
||||
router.Get("/fields", c.Getlistcustom)
|
||||
|
||||
router.Patch("/fields", c.Updatelistcustom)
|
||||
|
||||
router.Get("/pipelines", c.Getlistpipelines)
|
||||
|
||||
router.Patch("/pipelines", c.Updatelistpipelines)
|
||||
|
||||
router.Get("/steps", c.Getliststeps)
|
||||
|
||||
router.Patch("/steps", c.Updateliststeps)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *DifferentController) Getlisttags(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Getlisttags
|
||||
|
||||
err := c.DifferentService.Getlisttags(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Updatelisttags(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Updatelisttags
|
||||
|
||||
err := c.DifferentService.Updatelisttags(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Webhookcreate(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Webhookcreate
|
||||
|
||||
err := c.DifferentService.Webhookcreate(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Webhookdelete(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Webhookdelete
|
||||
|
||||
err := c.DifferentService.Webhookdelete(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Getlistcustom(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Getlistcustom
|
||||
|
||||
err := c.DifferentService.Getlistcustom(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Updatelistcustom(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Updatelistcustom
|
||||
|
||||
err := c.DifferentService.Updatelistcustom(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Getlistpipelines(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Getlistpipelines
|
||||
|
||||
err := c.DifferentService.Getlistpipelines(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Updatelistpipelines(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Updatelistpipelines
|
||||
|
||||
err := c.DifferentService.Updatelistpipelines(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Getliststeps(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Getliststeps
|
||||
|
||||
err := c.DifferentService.Getliststeps(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
||||
|
||||
func (c *DifferentController) Updateliststeps(ctx *fiber.Ctx) error {
|
||||
// Обработчик для метода Updateliststeps
|
||||
|
||||
err := c.DifferentService.Updateliststeps(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
|
||||
}
|
6
internal/models/connectaccountresp.go
Normal file
6
internal/models/connectaccountresp.go
Normal file
@ -0,0 +1,6 @@
|
||||
package models
|
||||
|
||||
type ConnectAccountResp struct {
|
||||
/* - ссылка для авторизации в амо*/
|
||||
Link string `json:"link"`
|
||||
}
|
18
internal/models/getcurrentaccountresp.go
Normal file
18
internal/models/getcurrentaccountresp.go
Normal file
@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
type GetCurrentAccountResp struct {
|
||||
/* - связь с аккаунтом в квизе*/
|
||||
Accountid string `json:"AccountID"`
|
||||
/* - айдишник пользвателя, который подключал интеграцию*/
|
||||
Amouserid int `json:"AmoUserID"`
|
||||
/* - связь с аккаунтом в амо*/
|
||||
Amocrmid int `json:"AmocrmID"`
|
||||
/* - страна указанная в настройках амо*/
|
||||
Country string `json:"Country"`
|
||||
/* - uuid*/
|
||||
ID string `json:"ID"`
|
||||
/* - имя аккаунта в амо*/
|
||||
Name string `json:"Name"`
|
||||
/* - поддомен организации в амо*/
|
||||
Subdomain string `json:"Subdomain"`
|
||||
}
|
48
internal/repository/account.go
Normal file
48
internal/repository/account.go
Normal file
@ -0,0 +1,48 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
type AccountRepository struct {
|
||||
}
|
||||
|
||||
func NewAccountRepository() *AccountRepository {
|
||||
return &AccountRepository{}
|
||||
}
|
||||
|
||||
func (r *AccountRepository) Getlistusers(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *AccountRepository) Updatelistusers(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *AccountRepository) Softdeleteaccount(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *AccountRepository) Getcurrentaccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetCurrentAccountResp{}, nil
|
||||
|
||||
}
|
||||
|
||||
func (r *AccountRepository) Connectaccount(ctx context.Context) (*models.ConnectAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.ConnectAccountResp{}, nil
|
||||
|
||||
}
|
82
internal/repository/different.go
Normal file
82
internal/repository/different.go
Normal file
@ -0,0 +1,82 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type DifferentRepository struct {
|
||||
}
|
||||
|
||||
func NewDifferentRepository() *DifferentRepository {
|
||||
return &DifferentRepository{}
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Getlisttags(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Updatelisttags(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Webhookcreate(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Webhookdelete(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Getlistcustom(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Updatelistcustom(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Getlistpipelines(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Updatelistpipelines(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Getliststeps(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) Updateliststeps(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
62
internal/server/http/http.go
Normal file
62
internal/server/http/http.go
Normal file
@ -0,0 +1,62 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
Controllers []Controller
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Controllers []Controller
|
||||
app *fiber.App
|
||||
}
|
||||
|
||||
func NewServer(config ServerConfig) *Server {
|
||||
app := fiber.New()
|
||||
|
||||
s := &Server{
|
||||
Controllers: config.Controllers,
|
||||
app: app,
|
||||
}
|
||||
|
||||
s.registerRoutes()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Server) Start(addr string) error {
|
||||
if err := s.app.Listen(addr); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) Shutdown(ctx context.Context) error {
|
||||
return s.app.Shutdown()
|
||||
}
|
||||
|
||||
func (s *Server) registerRoutes() {
|
||||
for _, c := range s.Controllers {
|
||||
router := s.app.Group(c.Name())
|
||||
c.Register(router)
|
||||
}
|
||||
}
|
||||
|
||||
type Controller interface {
|
||||
Register(router fiber.Router)
|
||||
Name() string
|
||||
}
|
||||
|
||||
func (s *Server) ListRoutes() {
|
||||
fmt.Println("Registered routes:")
|
||||
for _, stack := range s.app.Stack() {
|
||||
for _, route := range stack {
|
||||
fmt.Printf("%s %s\n", route.Method, route.Path)
|
||||
}
|
||||
}
|
||||
}
|
67
internal/service/account.go
Normal file
67
internal/service/account.go
Normal file
@ -0,0 +1,67 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/repository"
|
||||
"context"
|
||||
)
|
||||
|
||||
type AccountService struct {
|
||||
AccountRepository *repository.AccountRepository
|
||||
}
|
||||
|
||||
func NewAccountService(repository *repository.AccountRepository) *AccountService {
|
||||
return &AccountService{
|
||||
AccountRepository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AccountService) Getlistusers(ctx context.Context) error {
|
||||
|
||||
err := s.AccountRepository.Getlistusers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *AccountService) Updatelistusers(ctx context.Context) error {
|
||||
|
||||
err := s.AccountRepository.Updatelistusers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *AccountService) Softdeleteaccount(ctx context.Context) error {
|
||||
|
||||
err := s.AccountRepository.Softdeleteaccount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *AccountService) Getcurrentaccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
|
||||
response, err := s.AccountRepository.Getcurrentaccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *AccountService) Connectaccount(ctx context.Context) (*models.ConnectAccountResp, error) {
|
||||
|
||||
response, err := s.AccountRepository.Connectaccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
|
||||
}
|
116
internal/service/different.go
Normal file
116
internal/service/different.go
Normal file
@ -0,0 +1,116 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/repository"
|
||||
"context"
|
||||
)
|
||||
|
||||
type DifferentService struct {
|
||||
DifferentRepository *repository.DifferentRepository
|
||||
}
|
||||
|
||||
func NewDifferentService(repository *repository.DifferentRepository) *DifferentService {
|
||||
return &DifferentService{
|
||||
DifferentRepository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DifferentService) Getlisttags(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Getlisttags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Updatelisttags(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Updatelisttags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Webhookcreate(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Webhookcreate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Webhookdelete(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Webhookdelete(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Getlistcustom(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Getlistcustom(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Updatelistcustom(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Updatelistcustom(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Getlistpipelines(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Getlistpipelines(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Updatelistpipelines(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Updatelistpipelines(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Getliststeps(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Getliststeps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *DifferentService) Updateliststeps(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.Updateliststeps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
@ -149,6 +149,7 @@ paths:
|
||||
responses:
|
||||
'200':
|
||||
description: okay
|
||||
# блупринт с таким роутом не работает надо будет пересмотреть такие пути
|
||||
/rules/{quizID}:
|
||||
get:
|
||||
operationId: GetQuizSettings
|
||||
|
161
template/.gitignore.tmpl
Normal file
161
template/.gitignore.tmpl
Normal file
@ -0,0 +1,161 @@
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,goland,go
|
||||
|
||||
### Go ###
|
||||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
|
||||
### GoLand ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
.idea
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### GoLand Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator-enh.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
.idea/codestream.xml
|
||||
|
||||
# Azure Toolkit for IntelliJ plugin
|
||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||
.idea/**/azureSettings.xml
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go
|
29
template/cmd/{{.ProjectName}}/main.go.tmpl
Normal file
29
template/cmd/{{.ProjectName}}/main.go.tmpl
Normal file
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"{{.Vars.ProjectName}}/internal/app"
|
||||
|
||||
"{{.Modules.logger.Import}}"
|
||||
"{{.Modules.logger.ImportCore}}"
|
||||
|
||||
"{{.Modules.env.Import}}"
|
||||
)
|
||||
|
||||
func main() {
|
||||
{{.Modules.logger.Declaration "logger"}}
|
||||
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
var config app.Config
|
||||
|
||||
{{.Modules.env.Declaration "config"}}
|
||||
|
||||
if err := app.Run(ctx, config, logger); err != nil {
|
||||
{{.Modules.logger.Message "Fatal" "Failed to run app" "Error" "err"}}
|
||||
}
|
||||
}
|
67
template/internal/app/app.go.tmpl
Normal file
67
template/internal/app/app.go.tmpl
Normal file
@ -0,0 +1,67 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"{{.Modules.logger.Import}}"
|
||||
)
|
||||
|
||||
{{.Modules.env.Struct}}
|
||||
|
||||
func Run(ctx context.Context, config Config, logger {{.Modules.logger.Type}}) error {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Error("Recovered from a panic", zap.Any("error", r))
|
||||
}
|
||||
}()
|
||||
|
||||
{{.Modules.logger.Message "info" "App started" "config" "config"}}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// Инициализация репозиториев
|
||||
{{range $key, $value := .LayersData.Repositories}}
|
||||
{{$key}}Repository := {{$value.PackageName}}.New{{$value.Name}}Repository()
|
||||
{{end}}
|
||||
|
||||
// Инициализация сервисов
|
||||
{{range $key, $value := .LayersData.Services}}
|
||||
{{$key}}Service := {{$value.PackageName}}.New{{$value.Name}}Service({{$key}}Repository)
|
||||
{{end}}
|
||||
|
||||
// Инициализация контроллеров
|
||||
{{range $key, $value := .LayersData.Controllers}}
|
||||
{{$key}}Controller := {{$value.PackageName}}.New{{$value.Name}}Controller({{$key}}Service)
|
||||
{{end}}
|
||||
|
||||
// Создание сервера
|
||||
server := {{.LayersData.ServerData}}.NewServer({{.LayersData.ServerData}}.ServerConfig{
|
||||
Controllers: []{{.LayersData.ServerData}}.Controller{
|
||||
{{range $key, $value := .LayersData.Controllers}}
|
||||
{{$key}}Controller,
|
||||
{{end}}
|
||||
},
|
||||
})
|
||||
|
||||
go func() {
|
||||
err := server.Start("Host + : + Port")
|
||||
if err != nil {
|
||||
logger.Error("Server startup error", zap.Error(err))
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
|
||||
// Вывод маршрутов
|
||||
server.ListRoutes()
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
logger.Info("App shutting down gracefully")
|
||||
|
||||
//TODO
|
||||
// Остановка сервера
|
||||
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user