mirror of
https://github.com/lwch/natpass.git
synced 2024-04-21 12:41:54 +00:00
修正logsize的解析问题
This commit is contained in:
@@ -2,6 +2,7 @@ package global
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"natpass/code/utils"
|
||||
"os"
|
||||
|
||||
"github.com/lwch/runtime"
|
||||
@@ -23,7 +24,7 @@ type Configure struct {
|
||||
Server string
|
||||
Enc [md5.Size]byte
|
||||
LogDir string
|
||||
LogSize int
|
||||
LogSize utils.Bytes
|
||||
LogRotate int
|
||||
Tunnels []Tunnel
|
||||
}
|
||||
@@ -34,9 +35,9 @@ func LoadConf(dir string) *Configure {
|
||||
Server string `yaml:"server"`
|
||||
Secret string `yaml:"secret"`
|
||||
Log struct {
|
||||
Dir string `yaml:"dir"`
|
||||
Size int `yaml:"size"`
|
||||
Rotate int `yaml:"rotate"`
|
||||
Dir string `yaml:"dir"`
|
||||
Size utils.Bytes `yaml:"size"`
|
||||
Rotate int `yaml:"rotate"`
|
||||
} `yaml:"log"`
|
||||
Tunnel []Tunnel `yaml:"tunnel"`
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ func main() {
|
||||
|
||||
cfg := global.LoadConf(*conf)
|
||||
|
||||
logging.SetSizeRotate(cfg.LogDir, "np-cli", cfg.LogSize, cfg.LogRotate, true)
|
||||
logging.SetSizeRotate(cfg.LogDir, "np-cli", int(cfg.LogSize.Bytes()), cfg.LogRotate, true)
|
||||
|
||||
conn, err := tls.Dial("tcp", cfg.Server, nil)
|
||||
runtime.Assert(err)
|
||||
|
||||
@@ -2,6 +2,7 @@ package global
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"natpass/code/utils"
|
||||
"os"
|
||||
|
||||
"github.com/lwch/runtime"
|
||||
@@ -14,7 +15,7 @@ type Configure struct {
|
||||
TLSKey string
|
||||
TLSCrt string
|
||||
LogDir string
|
||||
LogSize int
|
||||
LogSize utils.Bytes
|
||||
LogRotate int
|
||||
}
|
||||
|
||||
@@ -23,9 +24,9 @@ func LoadConf(dir string) *Configure {
|
||||
Listen uint16 `yaml:"listen"`
|
||||
Secret string `yaml:"secret"`
|
||||
Log struct {
|
||||
Dir string `yaml:"dir"`
|
||||
Size int `yaml:"size"`
|
||||
Rotate int `yaml:"rotate"`
|
||||
Dir string `yaml:"dir"`
|
||||
Size utils.Bytes `yaml:"size"`
|
||||
Rotate int `yaml:"rotate"`
|
||||
} `yaml:"log"`
|
||||
TLS struct {
|
||||
Key string `yaml:"key"`
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ func main() {
|
||||
|
||||
cfg := global.LoadConf(*conf)
|
||||
|
||||
logging.SetSizeRotate(cfg.LogDir, "np-svr", cfg.LogSize, cfg.LogRotate, true)
|
||||
logging.SetSizeRotate(cfg.LogDir, "np-svr", int(cfg.LogSize.Bytes()), cfg.LogRotate, true)
|
||||
|
||||
cert, err := tls.LoadX509KeyPair(cfg.TLSCrt, cfg.TLSKey)
|
||||
runtime.Assert(err)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package utils
|
||||
|
||||
import "github.com/dustin/go-humanize"
|
||||
|
||||
type Bytes uint64
|
||||
|
||||
func (bt *Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var str string
|
||||
err := unmarshal(&str)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := humanize.ParseBytes(str)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*bt = Bytes(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bt *Bytes) Bytes() uint64 {
|
||||
return uint64(*bt)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ module natpass
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/lwch/daemon v0.0.0-20210628111519-5911af6cec06
|
||||
github.com/lwch/logging v0.0.0-20210528090125-a154917d90c6
|
||||
github.com/lwch/runtime v0.0.0-20190520054850-8c97e19e0c6d
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
|
||||
Reference in New Issue
Block a user