use vue-gettext

This commit is contained in:
0xJacky 2022-02-19 09:52:59 +08:00
parent b8d5d03572
commit 35d144c678
61 changed files with 1929 additions and 412 deletions

View file

@ -63,7 +63,6 @@ func Analytic(c *gin.Context) {
cpuUserUsage := (cpuTimesAfter[0].User - cpuTimesBefore[0].User) / (float64(1000*threadNum) / 1000)
cpuSystemUsage := (cpuTimesAfter[0].System - cpuTimesBefore[0].System) / (float64(1000*threadNum) / 1000)
response["cpu_user"], _ = strconv.ParseFloat(fmt.Sprintf("%.2f",
cpuUserUsage*100), 64)

View file

@ -29,7 +29,7 @@ func GetBackupList(path string) (configs []ConfigBackupListItem) {
return
}
func GetBackup(id int) (config ConfigBackup) {
func GetBackup(id int) (config ConfigBackup) {
db.First(&config, id)
return

View file

@ -1,38 +1,38 @@
package model
type Curd struct {
Model interface{}
Model interface{}
}
func NewCurd(Model interface{}) *Curd {
return &Curd{Model: Model}
return &Curd{Model: Model}
}
func (c *Curd) GetList(dest interface{}) (err error) {
err = db.Model(c.Model).Scan(dest).Error
return
err = db.Model(c.Model).Scan(dest).Error
return
}
func (c *Curd) First(dest interface{}, conds ...interface{}) (err error) {
err = db.Model(c.Model).First(dest, conds).Error
return
err = db.Model(c.Model).First(dest, conds).Error
return
}
func (c *Curd) Add(value interface{}) (err error) {
err = db.Model(c.Model).Create(value).Error
if err != nil {
return err
}
err = db.Find(value).Error
return
err = db.Model(c.Model).Create(value).Error
if err != nil {
return err
}
err = db.Find(value).Error
return
}
func (c *Curd) Edit(orig interface{}, new interface{}) (err error) {
err = db.Model(orig).Updates(new).Error
return
err = db.Model(orig).Updates(new).Error
return
}
func (c *Curd) Delete(value interface{}, conds ...interface{}) (err error) {
err = db.Model(c.Model).Delete(value, conds).Error
return
err = db.Model(c.Model).Delete(value, conds).Error
return
}

View file

@ -1,36 +1,36 @@
package test
import (
"fmt"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/disk"
"github.com/shirou/gopsutil/v3/load"
"github.com/shirou/gopsutil/v3/mem"
"runtime"
"testing"
"time"
"fmt"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/disk"
"github.com/shirou/gopsutil/v3/load"
"github.com/shirou/gopsutil/v3/mem"
"runtime"
"testing"
"time"
)
func TestGoPsutil(t *testing.T) {
fmt.Println("os:", runtime.GOOS)
fmt.Println("threads:", runtime.GOMAXPROCS(0))
fmt.Println("os:", runtime.GOOS)
fmt.Println("threads:", runtime.GOMAXPROCS(0))
v, _ := mem.VirtualMemory()
v, _ := mem.VirtualMemory()
loadAvg, _ := load.Avg()
loadAvg, _ := load.Avg()
fmt.Println("loadavg", loadAvg.String())
fmt.Println("loadavg", loadAvg.String())
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
cpuTimesBefore, _ := cpu.Times(false)
time.Sleep(1000*time.Millisecond)
cpuTimesAfter, _ := cpu.Times(false)
threadNum := runtime.GOMAXPROCS(0)
fmt.Println(cpuTimesBefore[0].String(), "\n", cpuTimesAfter[0].String())
cpuUserUsage := (cpuTimesAfter[0].User - cpuTimesBefore[0].User) / (float64(1000*threadNum) / 1000)
cpuSystemUsage := (cpuTimesAfter[0].System - cpuTimesBefore[0].System) / (float64(1000*threadNum) / 1000)
fmt.Printf("%.2f, %.2f\n", cpuUserUsage*100, cpuSystemUsage*100)
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
cpuTimesBefore, _ := cpu.Times(false)
time.Sleep(1000 * time.Millisecond)
cpuTimesAfter, _ := cpu.Times(false)
threadNum := runtime.GOMAXPROCS(0)
fmt.Println(cpuTimesBefore[0].String(), "\n", cpuTimesAfter[0].String())
cpuUserUsage := (cpuTimesAfter[0].User - cpuTimesBefore[0].User) / (float64(1000*threadNum) / 1000)
cpuSystemUsage := (cpuTimesAfter[0].System - cpuTimesBefore[0].System) / (float64(1000*threadNum) / 1000)
fmt.Printf("%.2f, %.2f\n", cpuUserUsage*100, cpuSystemUsage*100)
diskUsage, _ := disk.Usage(".")
fmt.Println(diskUsage.String())
diskUsage, _ := disk.Usage(".")
fmt.Println(diskUsage.String())
}

View file

@ -1,98 +1,94 @@
package test
import (
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"fmt"
"io/ioutil"
"log"
"testing"
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"fmt"
"io/ioutil"
"log"
"testing"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/challenge/http01"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/challenge/http01"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"
)
// You'll need a user or account type that implements acme.User
type MyUser struct {
Email string
Registration *registration.Resource
key crypto.PrivateKey
Email string
Registration *registration.Resource
key crypto.PrivateKey
}
func (u *MyUser) GetEmail() string {
return u.Email
return u.Email
}
func (u MyUser) GetRegistration() *registration.Resource {
return u.Registration
return u.Registration
}
func (u *MyUser) GetPrivateKey() crypto.PrivateKey {
return u.key
return u.key
}
func TestLego(t *testing.T) {
// Create a user. New accounts need an email and private key to start.
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
log.Fatal(err)
}
// Create a user. New accounts need an email and private key to start.
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
log.Fatal(err)
}
myUser := MyUser{
Email: "me@jackyu.cn",
key: privateKey,
}
myUser := MyUser{
Email: "me@jackyu.cn",
key: privateKey,
}
config := lego.NewConfig(&myUser)
config := lego.NewConfig(&myUser)
// This CA URL is configured for a local dev instance of Boulder running in Docker in a VM.
//config.CADirURL = "https://acme-staging-v02.api.letsencrypt.org/directory"
config.Certificate.KeyType = certcrypto.RSA2048
// This CA URL is configured for a local dev instance of Boulder running in Docker in a VM.
//config.CADirURL = "https://acme-staging-v02.api.letsencrypt.org/directory"
config.Certificate.KeyType = certcrypto.RSA2048
// A client facilitates communication with the CA server.
client, err := lego.NewClient(config)
if err != nil {
log.Fatal(err)
}
// A client facilitates communication with the CA server.
client, err := lego.NewClient(config)
if err != nil {
log.Fatal(err)
}
err = client.Challenge.SetHTTP01Provider(http01.NewProviderServer("", "9180"))
if err != nil {
log.Fatal(err)
}
err = client.Challenge.SetHTTP01Provider(http01.NewProviderServer("", "9180"))
if err != nil {
log.Fatal(err)
}
// New users will need to register
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
if err != nil {
log.Fatal(err)
}
myUser.Registration = reg
request := certificate.ObtainRequest{
Domains: []string{"shanghai2.ojbk.me"},
Bundle: true,
}
certificates, err := client.Certificate.Obtain(request)
if err != nil {
log.Fatal(err)
}
// New users will need to register
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true})
if err != nil {
log.Fatal(err)
}
myUser.Registration = reg
request := certificate.ObtainRequest{
Domains: []string{"shanghai2.ojbk.me"},
Bundle: true,
}
certificates, err := client.Certificate.Obtain(request)
if err != nil {
log.Fatal(err)
}
// Each certificate comes back with the cert bytes, the bytes of the client's
// private key, and a certificate URL. SAVE THESE TO DISK.
fmt.Printf("%#v\n", certificates)
err = ioutil.WriteFile("fullchain.cer", certificates.Certificate, 0644)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile("private.key", certificates.PrivateKey, 0644)
if err != nil {
log.Fatal(err)
}
// Each certificate comes back with the cert bytes, the bytes of the client's
// private key, and a certificate URL. SAVE THESE TO DISK.
fmt.Printf("%#v\n", certificates)
err = ioutil.WriteFile("fullchain.cer", certificates.Certificate, 0644)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile("private.key", certificates.PrivateKey, 0644)
if err != nil {
log.Fatal(err)
}
}

View file

@ -8,7 +8,7 @@ import (
"testing"
)
func TestGetNginx(t *testing.T) {
func TestGetNginx(t *testing.T) {
out, err := exec.Command("nginx", "-V").CombinedOutput()
if err != nil {
log.Fatal(err)

View file

@ -1,62 +1,62 @@
package tool
import (
"github.com/gin-gonic/gin"
"sort"
"time"
"github.com/gin-gonic/gin"
"sort"
"time"
)
type MapsSort struct {
Key string
Type string
Order string
MapList []gin.H
Key string
Type string
Order string
MapList []gin.H
}
func boolToInt(b bool) int {
if b {
return 1
}
return 0
if b {
return 1
}
return 0
}
func (m MapsSort) Len() int {
return len(m.MapList)
return len(m.MapList)
}
func (m MapsSort) Less(i, j int) bool {
flag := false
flag := false
if m.Type == "int" {
flag = m.MapList[i][m.Key].(int) > m.MapList[j][m.Key].(int)
} else if m.Type == "bool" {
flag = boolToInt(m.MapList[i][m.Key].(bool)) > boolToInt(m.MapList[j][m.Key].(bool))
} else if m.Type == "bool" {
flag = m.MapList[i][m.Key].(string) > m.MapList[j][m.Key].(string)
} else if m.Type == "time" {
flag = m.MapList[i][m.Key].(time.Time).After(m.MapList[j][m.Key].(time.Time))
}
if m.Type == "int" {
flag = m.MapList[i][m.Key].(int) > m.MapList[j][m.Key].(int)
} else if m.Type == "bool" {
flag = boolToInt(m.MapList[i][m.Key].(bool)) > boolToInt(m.MapList[j][m.Key].(bool))
} else if m.Type == "bool" {
flag = m.MapList[i][m.Key].(string) > m.MapList[j][m.Key].(string)
} else if m.Type == "time" {
flag = m.MapList[i][m.Key].(time.Time).After(m.MapList[j][m.Key].(time.Time))
}
if m.Order == "asc" {
flag = !flag
}
if m.Order == "asc" {
flag = !flag
}
return flag
return flag
}
func (m MapsSort) Swap(i, j int) {
m.MapList[i], m.MapList[j] = m.MapList[j], m.MapList[i]
m.MapList[i], m.MapList[j] = m.MapList[j], m.MapList[i]
}
func Sort(key string, order string, Type string, maps []gin.H) []gin.H {
mapsSort := MapsSort{
Key: key,
MapList: maps,
Type: Type,
Order: order,
}
mapsSort := MapsSort{
Key: key,
MapList: maps,
Type: Type,
Order: order,
}
sort.Sort(mapsSort)
sort.Sort(mapsSort)
return mapsSort.MapList
return mapsSort.MapList
}