fix: 移除项目未使用代码 (#3948)

This commit is contained in:
ssongliu 2024-02-22 15:32:07 +08:00 committed by GitHub
parent 9a127d9afe
commit b668f55222
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 23 additions and 480 deletions

View file

@ -164,24 +164,6 @@ func (b *BaseApi) SearchPostgresql(c *gin.Context) {
})
}
// @Tags Database Postgresql
// @Summary List postgresql database names
// @Description 获取 postgresql 数据库列表
// @Accept json
// @Param request body dto.PageInfo true "request"
// @Success 200 {array} dto.PostgresqlOption
// @Security ApiKeyAuth
// @Router /databases/pg/options [get]
func (b *BaseApi) ListPostgresqlDBName(c *gin.Context) {
list, err := postgresqlService.ListDBOption()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
// @Tags Database Postgresql
// @Summary Load postgresql database from remote
// @Description 从服务器获取

View file

@ -5,7 +5,6 @@ import (
"time"
"github.com/dgraph-io/badger/v4"
"github.com/pkg/errors"
)
type Cache struct {
@ -18,18 +17,6 @@ func NewCacheDB(db *badger.DB) *Cache {
}
}
func (c *Cache) SetNX(key string, value interface{}) error {
err := c.db.Update(func(txn *badger.Txn) error {
_, err := txn.Get([]byte(key))
if errors.Is(err, badger.ErrKeyNotFound) {
v := []byte(fmt.Sprintf("%v", value))
return txn.Set([]byte(key), v)
}
return err
})
return err
}
func (c *Cache) Set(key string, value interface{}) error {
err := c.db.Update(func(txn *badger.Txn) error {
v := []byte(fmt.Sprintf("%v", value))

View file

@ -3,7 +3,6 @@ package common
import (
"crypto/rand"
"fmt"
"golang.org/x/net/idna"
"io"
mathRand "math/rand"
"net"
@ -15,6 +14,8 @@ import (
"time"
"unicode"
"golang.org/x/net/idna"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
)
@ -143,15 +144,6 @@ func ScanPortWithProto(port int, proto string) bool {
return ScanPort(port)
}
func ExistWithStrArray(str string, arr []string) bool {
for _, a := range arr {
if strings.Contains(a, str) {
return true
}
}
return false
}
func IsNum(s string) bool {
_, err := strconv.ParseFloat(s, 64)
return err == nil

View file

@ -2,6 +2,11 @@ package docker
import (
"context"
"path"
"regexp"
"strings"
"time"
"github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command"
@ -10,10 +15,6 @@ import (
"github.com/docker/compose/v2/pkg/compose"
"github.com/docker/docker/client"
"github.com/joho/godotenv"
"path"
"regexp"
"strings"
"time"
)
type ComposeService struct {
@ -21,50 +22,6 @@ type ComposeService struct {
project *types.Project
}
func (s ComposeService) SetProject(project *types.Project) {
s.project = project
for i, s := range project.Services {
s.CustomLabels = map[string]string{
api.ProjectLabel: project.Name,
api.ServiceLabel: s.Name,
api.VersionLabel: api.ComposeVersion,
api.WorkingDirLabel: project.WorkingDir,
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
api.OneoffLabel: "False",
}
project.Services[i] = s
}
}
func (s ComposeService) ComposeUp() error {
return s.Up(context.Background(), s.project, api.UpOptions{
Create: api.CreateOptions{
Timeout: getComposeTimeout(),
},
Start: api.StartOptions{
WaitTimeout: *getComposeTimeout(),
},
})
}
func NewComposeService(ops ...command.DockerCliOption) (*ComposeService, error) {
apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return nil, err
}
ops = append(ops, command.WithAPIClient(apiClient), command.WithDefaultContextStoreConfig())
cli, err := command.NewDockerCli(ops...)
if err != nil {
return nil, err
}
cliOp := flags.NewClientOptions()
if err := cli.Initialize(cliOp); err != nil {
return nil, err
}
service := compose.NewComposeService(cli)
return &ComposeService{service, nil}, nil
}
func UpComposeProject(project *types.Project) error {
for i, s := range project.Services {
s.CustomLabels = map[string]string{

View file

@ -2,6 +2,7 @@ package docker
import (
"context"
"github.com/docker/docker/api/types/container"
"github.com/1Panel-dev/1Panel/backend/app/model"
@ -45,15 +46,6 @@ func NewDockerClient() (*client.Client, error) {
return cli, nil
}
func (c Client) ListAllContainers() ([]types.Container, error) {
var options container.ListOptions
containers, err := c.cli.ContainerList(context.Background(), options)
if err != nil {
return nil, err
}
return containers, nil
}
func (c Client) ListContainersByName(names []string) ([]types.Container, error) {
var (
options container.ListOptions

View file

@ -4,10 +4,8 @@ import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
@ -61,12 +59,6 @@ func StringDecrypt(text string) (string, error) {
return "", err
}
func Md5(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
func padding(plaintext []byte, blockSize int) []byte {
padding := blockSize - len(plaintext)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)

View file

@ -7,11 +7,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
http2 "github.com/1Panel-dev/1Panel/backend/utils/http"
cZip "github.com/klauspost/compress/zip"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"io"
"io/fs"
"net/http"
@ -23,6 +18,12 @@ import (
"sync"
"time"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
http2 "github.com/1Panel-dev/1Panel/backend/utils/http"
cZip "github.com/klauspost/compress/zip"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/mholt/archiver/v4"
"github.com/pkg/errors"
@ -85,10 +86,6 @@ func (f FileOp) DeleteFile(dst string) error {
return f.Fs.Remove(dst)
}
func (f FileOp) Delete(dst string) error {
return os.RemoveAll(dst)
}
func (f FileOp) CleanDir(dst string) error {
return cmd.ExecCmd(fmt.Sprintf("rm -rf %s/*", dst))
}
@ -129,14 +126,6 @@ func (f FileOp) SaveFile(dst string, content string, mode fs.FileMode) error {
return nil
}
func (f FileOp) Chmod(dst string, mode fs.FileMode) error {
return f.Fs.Chmod(dst, mode)
}
func (f FileOp) Chown(dst string, uid int, gid int) error {
return f.Fs.Chown(dst, uid, gid)
}
func (f FileOp) ChownR(dst string, uid string, gid string, sub bool) error {
cmdStr := fmt.Sprintf(`chown %s:%s "%s"`, uid, gid, dst)
if sub {
@ -563,40 +552,6 @@ func (f FileOp) Decompress(srcFile string, dst string, cType CompressType) error
return nil
}
func (f FileOp) Backup(srcFile string) (string, error) {
backupPath := srcFile + "_bak"
info, _ := f.Fs.Stat(backupPath)
if info != nil {
if info.IsDir() {
_ = f.DeleteDir(backupPath)
} else {
_ = f.DeleteFile(backupPath)
}
}
if err := f.Rename(srcFile, backupPath); err != nil {
return backupPath, err
}
return backupPath, nil
}
func (f FileOp) CopyAndBackup(src string) (string, error) {
backupPath := src + "_bak"
info, _ := f.Fs.Stat(backupPath)
if info != nil {
if info.IsDir() {
_ = f.DeleteDir(backupPath)
} else {
_ = f.DeleteFile(backupPath)
}
}
_ = f.CreateDir(backupPath, 0755)
if err := f.Copy(src, backupPath); err != nil {
return backupPath, err
}
return backupPath, nil
}
func ZipFile(files []archiver.File, dst afero.File) error {
zw := zip.NewWriter(dst)
defer zw.Close()

View file

@ -17,20 +17,3 @@ func GetIniValue(filePath, Group, Key string) (string, error) {
}
return startKey.Value(), nil
}
func SetIniValue(filePath, Group, Key, value string) error {
cfg, err := ini.Load(filePath)
if err != nil {
return err
}
service, err := cfg.GetSection(Group)
if err != nil {
return err
}
targetKey := service.Key(Key)
if err != nil {
return err
}
targetKey.SetValue(value)
return cfg.SaveTo(filePath)
}

View file

@ -102,25 +102,6 @@ var formatMap = map[string]string{
"big5": "big5_chinese_ci",
}
func VerifyPeerCertFunc(pool *x509.CertPool) func([][]byte, [][]*x509.Certificate) error {
return func(rawCerts [][]byte, _ [][]*x509.Certificate) error {
if len(rawCerts) == 0 {
return errors.New("no certificates available to verify")
}
cert, err := x509.ParseCertificate(rawCerts[0])
if err != nil {
return err
}
opts := x509.VerifyOptions{Roots: pool}
if _, err = cert.Verify(opts); err != nil {
return err
}
return nil
}
}
func ConnWithSSL(ssl, skipVerify bool, clientKey, clientCert, rootCert string) (string, error) {
if !ssl {
return "", nil

View file

@ -38,18 +38,6 @@ func WithData() DumpOption {
}
}
func WithTables(tables ...string) DumpOption {
return func(option *dumpOption) {
option.tables = tables
}
}
func WithAllTable() DumpOption {
return func(option *dumpOption) {
option.isAllTable = true
}
}
func WithWriter(writer io.Writer) DumpOption {
return func(option *dumpOption) {
option.writer = writer

View file

@ -19,24 +19,12 @@ type sourceOption struct {
}
type SourceOption func(*sourceOption)
func WithDryRun() SourceOption {
return func(o *sourceOption) {
o.dryRun = true
}
}
func WithMergeInsert(size int) SourceOption {
return func(o *sourceOption) {
o.mergeInsert = size
}
}
func WithDebug() SourceOption {
return func(o *sourceOption) {
o.debug = true
}
}
type dbWrapper struct {
DB *sql.DB
debug bool

View file

@ -5,19 +5,6 @@ type Config struct {
FilePath string
}
func (c *Config) FindDirectives(directiveName string) []IDirective {
return c.Block.FindDirectives(directiveName)
}
func (c *Config) FindUpstreams() []*Upstream {
var upstreams []*Upstream
directives := c.Block.FindDirectives("upstream")
for _, directive := range directives {
upstreams = append(upstreams, directive.(*Upstream))
}
return upstreams
}
func (c *Config) FindServers() []*Server {
var servers []*Server
directives := c.Block.FindDirectives("server")

View file

@ -1,14 +0,0 @@
package nginx
import (
"github.com/1Panel-dev/1Panel/backend/utils/nginx/components"
"github.com/1Panel-dev/1Panel/backend/utils/nginx/parser"
)
func GetConfig(path string) (*components.Config, error) {
p, err := parser.NewParser(path)
if err != nil {
return nil, err
}
return p.Parse()
}

View file

@ -1,21 +0,0 @@
package nginx
import (
"fmt"
"testing"
)
func TestNginx(t *testing.T) {
//config, err := GetConfig("/opt/1Panel/data/apps/nginx/nginx-1/conf/conf.d/word-1.conf")
config, err := GetConfig("/opt/1Panel/data/apps/nginx/nginx-new/conf/conf.d/1panel.cloud.conf")
if err != nil {
panic(err)
}
//server := config.FindServers()[0]
//fmt.Println(server)
//serverD := config.FindServers()[0]
//serverD.AddListen("8989", false)
fmt.Println(DumpConfig(config, IndentedStyle))
}

View file

@ -1,9 +1,5 @@
package flag
import (
"fmt"
)
type Type int
const (
@ -47,33 +43,13 @@ type Flag struct {
Column int
}
func (t Flag) String() string {
return fmt.Sprintf("{Type:%s,Literal:\"%s\",Line:%d,Column:%d}", t.Type, t.Literal, t.Line, t.Column)
}
func (t Flag) Lit(literal string) Flag {
t.Literal = literal
return t
}
func (t Flag) EqualTo(t2 Flag) bool {
return t.Type == t2.Type && t.Literal == t2.Literal
}
type Flags []Flag
func (fs Flags) EqualTo(flags Flags) bool {
if len(fs) != len(flags) {
return false
}
for i, t := range fs {
if !t.EqualTo(flags[i]) {
return false
}
}
return true
}
func (t Flag) Is(typ Type) bool {
return t.Type == typ
}

View file

@ -3,6 +3,8 @@ package ssl
import (
"crypto"
"encoding/json"
"time"
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/go-acme/lego/v4/acme"
"github.com/go-acme/lego/v4/acme/api"
@ -21,7 +23,6 @@ import (
"github.com/go-acme/lego/v4/providers/http/webroot"
"github.com/go-acme/lego/v4/registration"
"github.com/pkg/errors"
"time"
)
type AcmeUser struct {
@ -204,23 +205,6 @@ func (c *AcmeClient) ObtainSSL(domains []string, privateKey crypto.PrivateKey) (
return *certificates, nil
}
func (c *AcmeClient) RenewSSL(certUrl string) (certificate.Resource, error) {
certificates, err := c.Client.Certificate.Get(certUrl, true)
if err != nil {
return certificate.Resource{}, err
}
certificates, err = c.Client.Certificate.RenewWithOptions(*certificates, &certificate.RenewOptions{
Bundle: true,
PreferredChain: "",
MustStaple: true,
})
if err != nil {
return certificate.Resource{}, err
}
return *certificates, nil
}
type Resolve struct {
Key string
Value string

View file

@ -3,15 +3,16 @@ package websocket
import (
"encoding/json"
"fmt"
"sort"
"strings"
"sync"
"time"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/net"
"github.com/shirou/gopsutil/v3/process"
"sort"
"strings"
"sync"
"time"
)
type WsInput struct {
@ -86,18 +87,6 @@ type processConnect struct {
type ProcessConnects []processConnect
func (p ProcessConnects) Len() int {
return len(p)
}
func (p ProcessConnects) Less(i, j int) bool {
return p[i].PID < p[j].PID
}
func (p ProcessConnects) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
type sshSession struct {
Username string `json:"username"`
PID int32 `json:"PID"`

View file

@ -1,5 +1,5 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
// Code generated by swaggo/swag. DO NOT EDIT.
package docs
import "github.com/swaggo/swag"
@ -4954,45 +4954,6 @@ const docTemplate = `{
}
}
},
"/databases/pg/options": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取 postgresql 数据库列表",
"consumes": [
"application/json"
],
"tags": [
"Database Postgresql"
],
"summary": "List postgresql database names",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.PageInfo"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.PostgresqlOption"
}
}
}
}
}
},
"/databases/pg/password": {
"post": {
"security": [
@ -17203,26 +17164,6 @@ const docTemplate = `{
}
}
},
"dto.PostgresqlOption": {
"type": "object",
"properties": {
"database": {
"type": "string"
},
"from": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"dto.RecordSearch": {
"type": "object",
"required": [

View file

@ -4947,45 +4947,6 @@
}
}
},
"/databases/pg/options": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "获取 postgresql 数据库列表",
"consumes": [
"application/json"
],
"tags": [
"Database Postgresql"
],
"summary": "List postgresql database names",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.PageInfo"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.PostgresqlOption"
}
}
}
}
}
},
"/databases/pg/password": {
"post": {
"security": [
@ -17196,26 +17157,6 @@
}
}
},
"dto.PostgresqlOption": {
"type": "object",
"properties": {
"database": {
"type": "string"
},
"from": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"dto.RecordSearch": {
"type": "object",
"required": [

View file

@ -2119,19 +2119,6 @@ definitions:
- from
- type
type: object
dto.PostgresqlOption:
properties:
database:
type: string
from:
type: string
id:
type: integer
name:
type: string
type:
type: string
type: object
dto.RecordSearch:
properties:
detailName:
@ -8140,30 +8127,6 @@ paths:
[description]
formatZH: postgresql 数据库 [name] 描述信息修改 [description]
paramKeys: []
/databases/pg/options:
get:
consumes:
- application/json
description: 获取 postgresql 数据库列表
parameters:
- description: request
in: body
name: request
required: true
schema:
$ref: '#/definitions/dto.PageInfo'
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/dto.PostgresqlOption'
type: array
security:
- ApiKeyAuth: []
summary: List postgresql database names
tags:
- Database Postgresql
/databases/pg/password:
post:
consumes: