style: format go code with tab indent #605

This commit is contained in:
Jacky 2024-10-14 09:24:48 +08:00
parent 96cff98c66
commit 598d91a417
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
15 changed files with 244 additions and 251 deletions

View file

@ -9,8 +9,8 @@ insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.go] [*.go]
indent_style = tab
indent_size = 4 indent_size = 4
[README.md] [README.md]
indent_style = space
indent_size = 4 indent_size = 4

View file

@ -1,27 +1,26 @@
package certificate package certificate
import ( import (
"github.com/0xJacky/Nginx-UI/internal/cert/dns" "github.com/0xJacky/Nginx-UI/internal/cert/dns"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http" "net/http"
) )
func GetDNSProvidersList(c *gin.Context) { func GetDNSProvidersList(c *gin.Context) {
c.JSON(http.StatusOK, dns.GetProvidersList()) c.JSON(http.StatusOK, dns.GetProvidersList())
} }
func GetDNSProvider(c *gin.Context) { func GetDNSProvider(c *gin.Context) {
code := c.Param("code") code := c.Param("code")
provider, ok := dns.GetProvider(code) provider, ok := dns.GetProvider(code)
if !ok { if !ok {
c.JSON(http.StatusNotFound, gin.H{ c.JSON(http.StatusNotFound, gin.H{
"message": "provider not found", "message": "provider not found",
}) })
return return
} }
c.JSON(http.StatusOK, provider) c.JSON(http.StatusOK, provider)
} }

View file

@ -1,97 +1,97 @@
package config package config
import ( import (
"github.com/0xJacky/Nginx-UI/api" "github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/config" "github.com/0xJacky/Nginx-UI/internal/config"
"github.com/0xJacky/Nginx-UI/internal/helper" "github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/0xJacky/Nginx-UI/internal/nginx" "github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/query" "github.com/0xJacky/Nginx-UI/query"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/sashabaranov/go-openai" "github.com/sashabaranov/go-openai"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
) )
func AddConfig(c *gin.Context) { func AddConfig(c *gin.Context) {
var json struct { var json struct {
Name string `json:"name" binding:"required"` Name string `json:"name" binding:"required"`
NewFilepath string `json:"new_filepath" binding:"required"` NewFilepath string `json:"new_filepath" binding:"required"`
Content string `json:"content"` Content string `json:"content"`
Overwrite bool `json:"overwrite"` Overwrite bool `json:"overwrite"`
SyncNodeIds []int `json:"sync_node_ids"` SyncNodeIds []int `json:"sync_node_ids"`
} }
if !api.BindAndValid(c, &json) { if !api.BindAndValid(c, &json) {
return return
} }
name := json.Name name := json.Name
content := json.Content content := json.Content
path := json.NewFilepath path := json.NewFilepath
if !helper.IsUnderDirectory(path, nginx.GetConfPath()) { if !helper.IsUnderDirectory(path, nginx.GetConfPath()) {
c.JSON(http.StatusForbidden, gin.H{ c.JSON(http.StatusForbidden, gin.H{
"message": "new filepath is not under the nginx conf path", "message": "new filepath is not under the nginx conf path",
}) })
return return
} }
if !json.Overwrite && helper.FileExists(path) { if !json.Overwrite && helper.FileExists(path) {
c.JSON(http.StatusNotAcceptable, gin.H{ c.JSON(http.StatusNotAcceptable, gin.H{
"message": "File exists", "message": "File exists",
}) })
return return
} }
// check if the dir exists, if not, use mkdirAll to create the dir // check if the dir exists, if not, use mkdirAll to create the dir
dir := filepath.Dir(path) dir := filepath.Dir(path)
if !helper.FileExists(dir) { if !helper.FileExists(dir) {
err := os.MkdirAll(dir, 0755) err := os.MkdirAll(dir, 0755)
if err != nil { if err != nil {
api.ErrHandler(c, err) api.ErrHandler(c, err)
return return
} }
} }
err := os.WriteFile(path, []byte(content), 0644) err := os.WriteFile(path, []byte(content), 0644)
if err != nil { if err != nil {
api.ErrHandler(c, err) api.ErrHandler(c, err)
return return
} }
output := nginx.Reload() output := nginx.Reload()
if nginx.GetLogLevel(output) >= nginx.Warn { if nginx.GetLogLevel(output) >= nginx.Warn {
c.JSON(http.StatusInternalServerError, gin.H{ c.JSON(http.StatusInternalServerError, gin.H{
"message": output, "message": output,
}) })
return return
} }
q := query.Config q := query.Config
_, err = q.Where(q.Filepath.Eq(path)).Delete() _, err = q.Where(q.Filepath.Eq(path)).Delete()
if err != nil { if err != nil {
api.ErrHandler(c, err) api.ErrHandler(c, err)
return return
} }
err = q.Create(&model.Config{ err = q.Create(&model.Config{
Name: name, Name: name,
Filepath: path, Filepath: path,
SyncNodeIds: json.SyncNodeIds, SyncNodeIds: json.SyncNodeIds,
SyncOverwrite: json.Overwrite, SyncOverwrite: json.Overwrite,
}) })
if err != nil { if err != nil {
api.ErrHandler(c, err) api.ErrHandler(c, err)
return return
} }
c.JSON(http.StatusOK, config.Config{ c.JSON(http.StatusOK, config.Config{
Name: name, Name: name,
Content: content, Content: content,
ChatGPTMessages: make([]openai.ChatCompletionMessage, 0), ChatGPTMessages: make([]openai.ChatCompletionMessage, 0),
FilePath: path, FilePath: path,
ModifiedAt: time.Now(), ModifiedAt: time.Now(),
}) })
} }

View file

@ -1,59 +1,59 @@
package nginx package nginx
import ( import (
"github.com/0xJacky/Nginx-UI/api" "github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/nginx" "github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http" "net/http"
) )
func BuildNginxConfig(c *gin.Context) { func BuildNginxConfig(c *gin.Context) {
var ngxConf nginx.NgxConfig var ngxConf nginx.NgxConfig
if !api.BindAndValid(c, &ngxConf) { if !api.BindAndValid(c, &ngxConf) {
return return
} }
content, err := ngxConf.BuildConfig() content, err := ngxConf.BuildConfig()
if err != nil { if err != nil {
api.ErrHandler(c, err) api.ErrHandler(c, err)
return return
} }
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"content": content, "content": content,
}) })
} }
func TokenizeNginxConfig(c *gin.Context) { func TokenizeNginxConfig(c *gin.Context) {
var json struct { var json struct {
Content string `json:"content" binding:"required"` Content string `json:"content" binding:"required"`
} }
if !api.BindAndValid(c, &json) { if !api.BindAndValid(c, &json) {
return return
} }
ngxConfig, err := nginx.ParseNgxConfigByContent(json.Content) ngxConfig, err := nginx.ParseNgxConfigByContent(json.Content)
if err != nil { if err != nil {
api.ErrHandler(c, err) api.ErrHandler(c, err)
return return
} }
c.JSON(http.StatusOK, ngxConfig) c.JSON(http.StatusOK, ngxConfig)
} }
func FormatNginxConfig(c *gin.Context) { func FormatNginxConfig(c *gin.Context) {
var json struct { var json struct {
Content string `json:"content" binding:"required"` Content string `json:"content" binding:"required"`
} }
if !api.BindAndValid(c, &json) { if !api.BindAndValid(c, &json) {
return return
} }
content, err := nginx.FmtCode(json.Content) content, err := nginx.FmtCode(json.Content)
if err != nil { if err != nil {
api.ErrHandler(c, err) api.ErrHandler(c, err)
return return
} }
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"content": content, "content": content,
}) })
} }

View file

@ -90,6 +90,7 @@ loadTranslations(route)
.ant-menu { .ant-menu {
border-right: 0 !important; border-right: 0 !important;
} }
&.ant-layout-sider-has-trigger { &.ant-layout-sider-has-trigger {
padding-bottom: 0; padding-bottom: 0;
} }

4
go.mod
View file

@ -34,7 +34,7 @@ require (
github.com/shopspring/decimal v1.4.0 github.com/shopspring/decimal v1.4.0
github.com/spf13/cast v1.7.0 github.com/spf13/cast v1.7.0
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
github.com/tufanbarisyildirim/gonginx v0.0.0-20240109151651-bb3e845a7a2a github.com/tufanbarisyildirim/gonginx v0.0.0-20241013191809-e73b7dd454e8
go.uber.org/zap v1.27.0 go.uber.org/zap v1.27.0
golang.org/x/crypto v0.28.0 golang.org/x/crypto v0.28.0
gopkg.in/guregu/null.v4 v4.0.0 gopkg.in/guregu/null.v4 v4.0.0
@ -268,5 +268,3 @@ require (
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
) )
replace github.com/tufanbarisyildirim/gonginx v0.0.0-20240109151651-bb3e845a7a2a => github.com/0xJacky/gonginx v0.0.0-20240119024214-c0d76957d0c7

13
go.sum
View file

@ -39,7 +39,6 @@ cloud.google.com/go v0.104.0/go.mod h1:OO6xxXdJyvuJPcEPBLN9BJPD+jep5G1+2U5B5gkRY
cloud.google.com/go v0.105.0/go.mod h1:PrLgOJNe5nfE9UMxKxgXj4mD3voiP+YQ6gdt6KMFOKM= cloud.google.com/go v0.105.0/go.mod h1:PrLgOJNe5nfE9UMxKxgXj4mD3voiP+YQ6gdt6KMFOKM=
cloud.google.com/go v0.107.0/go.mod h1:wpc2eNrD7hXUTy8EKS10jkxpZBjASrORK7goS+3YX2I= cloud.google.com/go v0.107.0/go.mod h1:wpc2eNrD7hXUTy8EKS10jkxpZBjASrORK7goS+3YX2I=
cloud.google.com/go v0.110.0/go.mod h1:SJnCLqQ0FCFGSZMUNUf84MV3Aia54kn7pi8st7tMzaY= cloud.google.com/go v0.110.0/go.mod h1:SJnCLqQ0FCFGSZMUNUf84MV3Aia54kn7pi8st7tMzaY=
cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ=
cloud.google.com/go/accessapproval v1.4.0/go.mod h1:zybIuC3KpDOvotz59lFe5qxRZx6C75OtwbisN56xYB4= cloud.google.com/go/accessapproval v1.4.0/go.mod h1:zybIuC3KpDOvotz59lFe5qxRZx6C75OtwbisN56xYB4=
cloud.google.com/go/accessapproval v1.5.0/go.mod h1:HFy3tuiGvMdcd/u+Cu5b9NkO1pEICJ46IR82PoUdplw= cloud.google.com/go/accessapproval v1.5.0/go.mod h1:HFy3tuiGvMdcd/u+Cu5b9NkO1pEICJ46IR82PoUdplw=
cloud.google.com/go/accessapproval v1.6.0/go.mod h1:R0EiYnwV5fsRFiKZkPHr6mwyk2wxUJ30nL4j2pcFY2E= cloud.google.com/go/accessapproval v1.6.0/go.mod h1:R0EiYnwV5fsRFiKZkPHr6mwyk2wxUJ30nL4j2pcFY2E=
@ -179,7 +178,6 @@ cloud.google.com/go/compute v1.14.0/go.mod h1:YfLtxrj9sU4Yxv+sXzZkyPjEyPBZfXHUvj
cloud.google.com/go/compute v1.15.1/go.mod h1:bjjoF/NtFUrkD/urWfdHaKuOPDR5nWIs63rR+SXhcpA= cloud.google.com/go/compute v1.15.1/go.mod h1:bjjoF/NtFUrkD/urWfdHaKuOPDR5nWIs63rR+SXhcpA=
cloud.google.com/go/compute v1.18.0/go.mod h1:1X7yHxec2Ga+Ss6jPyjxRxpu2uu7PLgsOVXvgU0yacs= cloud.google.com/go/compute v1.18.0/go.mod h1:1X7yHxec2Ga+Ss6jPyjxRxpu2uu7PLgsOVXvgU0yacs=
cloud.google.com/go/compute v1.19.0/go.mod h1:rikpw2y+UMidAe9tISo04EHNOIf42RLYF/q8Bs93scU= cloud.google.com/go/compute v1.19.0/go.mod h1:rikpw2y+UMidAe9tISo04EHNOIf42RLYF/q8Bs93scU=
cloud.google.com/go/compute v1.28.1 h1:XwPcZjgMCnU2tkwY10VleUjSAfpTj9RDn+kGrbYsi8o=
cloud.google.com/go/compute/metadata v0.1.0/go.mod h1:Z1VN+bulIf6bt4P/C37K4DyZYZEXYonfTBHHFPO/4UU= cloud.google.com/go/compute/metadata v0.1.0/go.mod h1:Z1VN+bulIf6bt4P/C37K4DyZYZEXYonfTBHHFPO/4UU=
cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
cloud.google.com/go/compute/metadata v0.2.1/go.mod h1:jgHgmJd2RKBGzXqF5LR2EZMGxBkeanZ9wwa75XHJgOM= cloud.google.com/go/compute/metadata v0.2.1/go.mod h1:jgHgmJd2RKBGzXqF5LR2EZMGxBkeanZ9wwa75XHJgOM=
@ -608,8 +606,6 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8= gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc= git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
github.com/0xJacky/gonginx v0.0.0-20240119024214-c0d76957d0c7 h1:Ry+bJ2b0JDOHz3LpNJwLbk8ucj2lLHv/oQhfua25EPQ=
github.com/0xJacky/gonginx v0.0.0-20240119024214-c0d76957d0c7/go.mod h1:4fTjBxMoWGOIVnGFSTS9GAZ0yMyiGzTdATQS0krQv18=
github.com/0xJacky/pofile v0.2.1 h1:ceNyprJOpo7wPPR0rCOuR1gfjYiS8t9YBc73tSLnlDc= github.com/0xJacky/pofile v0.2.1 h1:ceNyprJOpo7wPPR0rCOuR1gfjYiS8t9YBc73tSLnlDc=
github.com/0xJacky/pofile v0.2.1/go.mod h1:hOZmte1hWostNs9KCwFRhKM7hf0d19zfWosopngij74= github.com/0xJacky/pofile v0.2.1/go.mod h1:hOZmte1hWostNs9KCwFRhKM7hf0d19zfWosopngij74=
github.com/AdamSLevy/jsonrpc2/v14 v14.1.0 h1:Dy3M9aegiI7d7PF1LUdjbVigJReo+QOceYsMyFh9qoE= github.com/AdamSLevy/jsonrpc2/v14 v14.1.0 h1:Dy3M9aegiI7d7PF1LUdjbVigJReo+QOceYsMyFh9qoE=
@ -753,7 +749,6 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@ -803,8 +798,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/ristretto v0.2.0 h1:XAfl+7cmoUDWW/2Lx8TGZQjjxIQ2Ley9DSf52dru4WE=
github.com/dgraph-io/ristretto v0.2.0/go.mod h1:8uBHCU/PBV4Ag0CJrP47b9Ofby5dqWNh4FicAdoqFNU=
github.com/dgraph-io/ristretto v1.0.0 h1:SYG07bONKMlFDUYu5pEu3DGAh8c2OFNzKm6G9J4Si84= github.com/dgraph-io/ristretto v1.0.0 h1:SYG07bONKMlFDUYu5pEu3DGAh8c2OFNzKm6G9J4Si84=
github.com/dgraph-io/ristretto v1.0.0/go.mod h1:jTi2FiYEhQ1NsMmA7DeBykizjOuY88NhKBkepyu1jPc= github.com/dgraph-io/ristretto v1.0.0/go.mod h1:jTi2FiYEhQ1NsMmA7DeBykizjOuY88NhKBkepyu1jPc=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
@ -1577,6 +1570,8 @@ github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/transip/gotransip/v6 v6.26.0 h1:Aejfvh8rSp8Mj2GX/RpdBjMCv+Iy/DmgfNgczPDP550= github.com/transip/gotransip/v6 v6.26.0 h1:Aejfvh8rSp8Mj2GX/RpdBjMCv+Iy/DmgfNgczPDP550=
github.com/transip/gotransip/v6 v6.26.0/go.mod h1:x0/RWGRK/zob817O3tfO2xhFoP1vu8YOHORx6Jpk80s= github.com/transip/gotransip/v6 v6.26.0/go.mod h1:x0/RWGRK/zob817O3tfO2xhFoP1vu8YOHORx6Jpk80s=
github.com/tufanbarisyildirim/gonginx v0.0.0-20241013191809-e73b7dd454e8 h1:7yw1yHkylDcu/CwY4hEEe8MycDLo7B9LjcqwhoL8NrM=
github.com/tufanbarisyildirim/gonginx v0.0.0-20241013191809-e73b7dd454e8/go.mod h1:itu4KWRgrfEwGcfNka+rV4houuirUau53i0diN4lG5g=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
@ -2467,8 +2462,8 @@ gorm.io/hints v1.1.2 h1:b5j0kwk5p4+3BtDtYqqfY+ATSxjj+6ptPgVveuynn9o=
gorm.io/hints v1.1.2/go.mod h1:/ARdpUHAtyEMCh5NNi3tI7FsGh+Cj/MIUlvNxCNCFWg= gorm.io/hints v1.1.2/go.mod h1:/ARdpUHAtyEMCh5NNi3tI7FsGh+Cj/MIUlvNxCNCFWg=
gorm.io/plugin/dbresolver v1.5.3 h1:wFwINGZZmttuu9h7XpvbDHd8Lf9bb8GNzp/NpAMV2wU= gorm.io/plugin/dbresolver v1.5.3 h1:wFwINGZZmttuu9h7XpvbDHd8Lf9bb8GNzp/NpAMV2wU=
gorm.io/plugin/dbresolver v1.5.3/go.mod h1:TSrVhaUg2DZAWP3PrHlDlITEJmNOkL0tFTjvTEsQ4XE= gorm.io/plugin/dbresolver v1.5.3/go.mod h1:TSrVhaUg2DZAWP3PrHlDlITEJmNOkL0tFTjvTEsQ4XE=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View file

@ -1,19 +1,19 @@
package cert package cert
type ChannelWriter struct { type ChannelWriter struct {
Ch chan []byte Ch chan []byte
} }
func NewChannelWriter() *ChannelWriter { func NewChannelWriter() *ChannelWriter {
return &ChannelWriter{ return &ChannelWriter{
Ch: make(chan []byte, 1024), Ch: make(chan []byte, 1024),
} }
} }
func (cw *ChannelWriter) Write(p []byte) (n int, err error) { func (cw *ChannelWriter) Write(p []byte) (n int, err error) {
n = len(p) n = len(p)
temp := make([]byte, n) temp := make([]byte, n)
copy(temp, p) copy(temp, p)
cw.Ch <- temp cw.Ch <- temp
return n, nil return n, nil
} }

View file

@ -1,117 +1,117 @@
package cosy package cosy
import ( import (
"github.com/0xJacky/Nginx-UI/internal/logger" "github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"gorm.io/gorm" "gorm.io/gorm"
) )
var validate *validator.Validate var validate *validator.Validate
func init() { func init() {
validate = validator.New() validate = validator.New()
} }
type Ctx[T any] struct { type Ctx[T any] struct {
ctx *gin.Context ctx *gin.Context
rules gin.H rules gin.H
Payload map[string]interface{} Payload map[string]interface{}
Model T Model T
OriginModel T OriginModel T
table string table string
tableArgs []interface{} tableArgs []interface{}
abort bool abort bool
nextHandler *gin.HandlerFunc nextHandler *gin.HandlerFunc
skipAssociationsOnCreate bool skipAssociationsOnCreate bool
beforeDecodeHookFunc []func(ctx *Ctx[T]) beforeDecodeHookFunc []func(ctx *Ctx[T])
beforeExecuteHookFunc []func(ctx *Ctx[T]) beforeExecuteHookFunc []func(ctx *Ctx[T])
executedHookFunc []func(ctx *Ctx[T]) executedHookFunc []func(ctx *Ctx[T])
gormScopes []func(tx *gorm.DB) *gorm.DB gormScopes []func(tx *gorm.DB) *gorm.DB
preloads []string preloads []string
scan func(tx *gorm.DB) any scan func(tx *gorm.DB) any
transformer func(*T) any transformer func(*T) any
permanentlyDelete bool permanentlyDelete bool
SelectedFields []string SelectedFields []string
itemKey string itemKey string
} }
func Core[T any](c *gin.Context) *Ctx[T] { func Core[T any](c *gin.Context) *Ctx[T] {
return &Ctx[T]{ return &Ctx[T]{
ctx: c, ctx: c,
gormScopes: make([]func(tx *gorm.DB) *gorm.DB, 0), gormScopes: make([]func(tx *gorm.DB) *gorm.DB, 0),
beforeExecuteHookFunc: make([]func(ctx *Ctx[T]), 0), beforeExecuteHookFunc: make([]func(ctx *Ctx[T]), 0),
beforeDecodeHookFunc: make([]func(ctx *Ctx[T]), 0), beforeDecodeHookFunc: make([]func(ctx *Ctx[T]), 0),
itemKey: "`id`", itemKey: "`id`",
skipAssociationsOnCreate: true, skipAssociationsOnCreate: true,
} }
} }
func (c *Ctx[T]) SetTable(table string, args ...interface{}) *Ctx[T] { func (c *Ctx[T]) SetTable(table string, args ...interface{}) *Ctx[T] {
c.table = table c.table = table
c.tableArgs = args c.tableArgs = args
return c return c
} }
func (c *Ctx[T]) SetItemKey(key string) *Ctx[T] { func (c *Ctx[T]) SetItemKey(key string) *Ctx[T] {
c.itemKey = key c.itemKey = key
return c return c
} }
func (c *Ctx[T]) SetValidRules(rules gin.H) *Ctx[T] { func (c *Ctx[T]) SetValidRules(rules gin.H) *Ctx[T] {
c.rules = rules c.rules = rules
return c return c
} }
func (c *Ctx[T]) SetPreloads(args ...string) *Ctx[T] { func (c *Ctx[T]) SetPreloads(args ...string) *Ctx[T] {
c.preloads = append(c.preloads, args...) c.preloads = append(c.preloads, args...)
return c return c
} }
func (c *Ctx[T]) validate() (errs gin.H) { func (c *Ctx[T]) validate() (errs gin.H) {
c.Payload = make(gin.H) c.Payload = make(gin.H)
_ = c.ctx.ShouldBindJSON(&c.Payload) _ = c.ctx.ShouldBindJSON(&c.Payload)
errs = validate.ValidateMap(c.Payload, c.rules) errs = validate.ValidateMap(c.Payload, c.rules)
if len(errs) > 0 { if len(errs) > 0 {
logger.Debug(errs) logger.Debug(errs)
for k := range errs { for k := range errs {
errs[k] = c.rules[k] errs[k] = c.rules[k]
} }
return return
} }
// Make sure that the key in c.Payload is also the key of rules // Make sure that the key in c.Payload is also the key of rules
validated := make(map[string]interface{}) validated := make(map[string]interface{})
for k, v := range c.Payload { for k, v := range c.Payload {
if _, ok := c.rules[k]; ok { if _, ok := c.rules[k]; ok {
validated[k] = v validated[k] = v
} }
} }
c.Payload = validated c.Payload = validated
return return
} }
func (c *Ctx[T]) SetScan(scan func(tx *gorm.DB) any) *Ctx[T] { func (c *Ctx[T]) SetScan(scan func(tx *gorm.DB) any) *Ctx[T] {
c.scan = scan c.scan = scan
return c return c
} }
func (c *Ctx[T]) SetTransformer(t func(m *T) any) *Ctx[T] { func (c *Ctx[T]) SetTransformer(t func(m *T) any) *Ctx[T] {
c.transformer = t c.transformer = t
return c return c
} }
func (c *Ctx[T]) AbortWithError(err error) { func (c *Ctx[T]) AbortWithError(err error) {
c.abort = true c.abort = true
errHandler(c.ctx, err) errHandler(c.ctx, err)
} }
func (c *Ctx[T]) Abort() { func (c *Ctx[T]) Abort() {
c.abort = true c.abort = true
} }

View file

@ -3,7 +3,7 @@ package nginx
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/tufanbarisyildirim/gonginx" "github.com/tufanbarisyildirim/gonginx/dumper"
"github.com/tufanbarisyildirim/gonginx/parser" "github.com/tufanbarisyildirim/gonginx/parser"
"strings" "strings"
) )
@ -83,11 +83,11 @@ func (c *NgxConfig) BuildConfig() (content string, err error) {
content += fmt.Sprintf("%sserver {\n%s}\n\n", comments, server) content += fmt.Sprintf("%sserver {\n%s}\n\n", comments, server)
} }
p := parser.NewStringParser(content, parser.WithSkipValidDirectivesErr()) p := parser.NewStringParser(content, parser.WithSkipValidDirectivesErr())
config, err := p.Parse() cfg, err := p.Parse()
if err != nil { if err != nil {
return return
} }
content = gonginx.DumpConfig(config, gonginx.IndentedStyle) content = dumper.DumpConfig(cfg, dumper.IndentedStyle)
return return
} }

View file

@ -1,12 +1,12 @@
package nginx package nginx
import ( import (
"github.com/tufanbarisyildirim/gonginx" "github.com/tufanbarisyildirim/gonginx/dumper"
"github.com/tufanbarisyildirim/gonginx/parser" "github.com/tufanbarisyildirim/gonginx/parser"
) )
func (c *NgxConfig) FmtCode() (fmtContent string) { func (c *NgxConfig) FmtCode() (fmtContent string) {
fmtContent = gonginx.DumpConfig(c.c, gonginx.IndentedStyle) fmtContent = dumper.DumpConfig(c.c, dumper.IndentedStyle)
return return
} }
@ -16,6 +16,6 @@ func FmtCode(content string) (fmtContent string, err error) {
if err != nil { if err != nil {
return return
} }
fmtContent = gonginx.DumpConfig(c, gonginx.IndentedStyle) fmtContent = dumper.DumpConfig(c, dumper.IndentedStyle)
return return
} }

View file

@ -2,7 +2,7 @@ package nginx
import ( import (
"fmt" "fmt"
"github.com/tufanbarisyildirim/gonginx" "github.com/tufanbarisyildirim/gonginx/config"
"github.com/tufanbarisyildirim/gonginx/parser" "github.com/tufanbarisyildirim/gonginx/parser"
"strings" "strings"
"testing" "testing"
@ -32,7 +32,7 @@ func TestNgxConfParse(t *testing.T) {
fmt.Println(c) fmt.Println(c)
} }
func fn(block gonginx.IBlock, deep int) { func fn(block config.IBlock, deep int) {
if block == nil { if block == nil {
return return
} }

View file

@ -2,7 +2,7 @@ package nginx
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/tufanbarisyildirim/gonginx" "github.com/tufanbarisyildirim/gonginx/config"
"github.com/tufanbarisyildirim/gonginx/parser" "github.com/tufanbarisyildirim/gonginx/parser"
"strings" "strings"
) )
@ -13,11 +13,11 @@ const (
Upstream = "upstream" Upstream = "upstream"
) )
func (s *NgxServer) ParseServer(directive gonginx.IDirective) { func (s *NgxServer) ParseServer(directive config.IDirective) {
s.parseServer(directive) s.parseServer(directive)
} }
func (s *NgxServer) parseServer(directive gonginx.IDirective) { func (s *NgxServer) parseServer(directive config.IDirective) {
if directive.GetBlock() == nil { if directive.GetBlock() == nil {
return return
} }
@ -40,10 +40,10 @@ func (s *NgxServer) parseServer(directive gonginx.IDirective) {
} }
} }
} }
func (l *NgxLocation) ParseLocation(directive gonginx.IDirective, deep int) { func (l *NgxLocation) ParseLocation(directive config.IDirective, deep int) {
l.parseLocation(directive, deep) l.parseLocation(directive, deep)
} }
func (l *NgxLocation) parseLocation(directive gonginx.IDirective, deep int) { func (l *NgxLocation) parseLocation(directive config.IDirective, deep int) {
if directive.GetBlock() == nil { if directive.GetBlock() == nil {
return return
} }
@ -64,11 +64,11 @@ func (l *NgxLocation) parseLocation(directive gonginx.IDirective, deep int) {
} }
} }
func (d *NgxDirective) ParseDirective(directive gonginx.IDirective, deep int) { func (d *NgxDirective) ParseDirective(directive config.IDirective, deep int) {
d.parseDirective(directive, deep) d.parseDirective(directive, deep)
} }
func (d *NgxDirective) parseDirective(directive gonginx.IDirective, deep int) { func (d *NgxDirective) parseDirective(directive config.IDirective, deep int) {
if directive.GetBlock() != nil { if directive.GetBlock() != nil {
d.Params += directive.GetName() + " " d.Params += directive.GetName() + " "
d.Directive = "" d.Directive = ""
@ -97,7 +97,7 @@ func (d *NgxDirective) parseDirective(directive gonginx.IDirective, deep int) {
} }
} }
func (u *NgxUpstream) parseUpstream(directive gonginx.IDirective) { func (u *NgxUpstream) parseUpstream(directive config.IDirective) {
if directive.GetBlock() == nil { if directive.GetBlock() == nil {
return return
} }
@ -111,7 +111,7 @@ func (u *NgxUpstream) parseUpstream(directive gonginx.IDirective) {
} }
} }
func (c *NgxConfig) parseCustom(directive gonginx.IDirective) { func (c *NgxConfig) parseCustom(directive config.IDirective) {
if directive.GetBlock() == nil { if directive.GetBlock() == nil {
return return
} }
@ -127,7 +127,7 @@ func buildComment(c []string) string {
return strings.ReplaceAll(strings.Join(c, "\n"), "#", "") return strings.ReplaceAll(strings.Join(c, "\n"), "#", "")
} }
func parse(block gonginx.IBlock, ngxConfig *NgxConfig) (err error) { func parse(block config.IBlock, ngxConfig *NgxConfig) (err error) {
if block == nil { if block == nil {
err = errors.New("block is nil") err = errors.New("block is nil")
return return

View file

@ -1,7 +1,7 @@
package nginx package nginx
import ( import (
"github.com/tufanbarisyildirim/gonginx" "github.com/tufanbarisyildirim/gonginx/config"
"path" "path"
"strings" "strings"
) )
@ -12,7 +12,7 @@ type NgxConfig struct {
Upstreams []*NgxUpstream `json:"upstreams"` Upstreams []*NgxUpstream `json:"upstreams"`
Servers []*NgxServer `json:"servers"` Servers []*NgxServer `json:"servers"`
Custom string `json:"custom"` Custom string `json:"custom"`
c *gonginx.Config c *config.Config
} }
type NgxServer struct { type NgxServer struct {

View file

@ -2,8 +2,8 @@ package model
type Config struct { type Config struct {
Model Model
Name string `json:"name"` Name string `json:"name"`
Filepath string `json:"filepath"` Filepath string `json:"filepath"`
SyncNodeIds []int `json:"sync_node_ids" gorm:"serializer:json"` SyncNodeIds []int `json:"sync_node_ids" gorm:"serializer:json"`
SyncOverwrite bool `json:"sync_overwrite"` SyncOverwrite bool `json:"sync_overwrite"`
} }