Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions backend/app/api/v1/database_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 从服务器获取
Expand Down
13 changes: 0 additions & 13 deletions backend/init/cache/badger_db/badger_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/dgraph-io/badger/v4"
"github.com/pkg/errors"
)

type Cache struct {
Expand All @@ -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))
Expand Down
12 changes: 2 additions & 10 deletions backend/utils/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package common
import (
"crypto/rand"
"fmt"
"golang.org/x/net/idna"
"io"
mathRand "math/rand"
"net"
Expand All @@ -15,6 +14,8 @@ import (
"time"
"unicode"

"golang.org/x/net/idna"

"github.com/1Panel-dev/1Panel/backend/utils/cmd"
)

Expand Down Expand Up @@ -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
Expand Down
53 changes: 5 additions & 48 deletions backend/utils/docker/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -10,61 +15,13 @@ import (
"github.com/docker/compose/v2/pkg/compose"
"github.com/docker/docker/client"
"github.com/joho/godotenv"
"path"
"regexp"
"strings"
"time"
)

type ComposeService struct {
api.Service
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{
Expand Down
10 changes: 1 addition & 9 deletions backend/utils/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docker

import (
"context"

"github.com/docker/docker/api/types/container"

"github.com/1Panel-dev/1Panel/backend/app/model"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions backend/utils/encrypt/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"fmt"
"io"

Expand Down Expand Up @@ -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)
Expand Down
57 changes: 6 additions & 51 deletions backend/utils/files/file_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 0 additions & 17 deletions backend/utils/ini_conf/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
19 changes: 0 additions & 19 deletions backend/utils/mysql/client/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions backend/utils/mysql/helper/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions backend/utils/mysql/helper/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading