mirror of
https://github.com/eolinker/apinto
synced 2025-09-26 21:01:19 +08:00
处理过期语法
This commit is contained in:
@@ -3,7 +3,7 @@ package eureka
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
@@ -75,7 +75,7 @@ func (c *client) GetApplication(addr string, serviceName string) (*Application,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
respBody, err := ioutil.ReadAll(res.Body)
|
||||
respBody, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package eureka
|
||||
|
||||
import (
|
||||
"github.com/eolinker/apinto/drivers"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@@ -21,11 +22,10 @@ func TestGetApp(t *testing.T) {
|
||||
},
|
||||
}
|
||||
e := &eureka{
|
||||
id: "1",
|
||||
WorkerBase: drivers.Worker("1", name),
|
||||
|
||||
client: newClient(cfg.getAddress(), cfg.getParams()),
|
||||
nodes: discovery.NewNodesData(),
|
||||
services: discovery.NewServices(),
|
||||
services: discovery.NewAppContainer(),
|
||||
locker: sync.RWMutex{},
|
||||
}
|
||||
app, err := e.GetApp(serviceName)
|
||||
@@ -35,10 +35,5 @@ func TestGetApp(t *testing.T) {
|
||||
for _, node := range app.Nodes() {
|
||||
t.Log(node.ID())
|
||||
}
|
||||
ns, bo := e.nodes.Get(serviceName)
|
||||
if bo {
|
||||
t.Log(len(ns))
|
||||
} else {
|
||||
t.Error("nodes error")
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -74,8 +74,6 @@ type Connection interface {
|
||||
type gettyConn struct {
|
||||
id uint32
|
||||
compress CompressType
|
||||
padding1 uint8
|
||||
padding2 uint16
|
||||
readBytes uatomic.Uint32 // read bytes
|
||||
writeBytes uatomic.Uint32 // write bytes
|
||||
readPkgNum uatomic.Uint32 // send pkg number
|
||||
@@ -124,7 +122,7 @@ func (c *gettyConn) send(interface{}) (int, error) {
|
||||
|
||||
func (c *gettyConn) close(int) {}
|
||||
|
||||
func (c gettyConn) readTimeout() time.Duration {
|
||||
func (c *gettyConn) readTimeout() time.Duration {
|
||||
return c.rTimeout.Load()
|
||||
}
|
||||
|
||||
@@ -147,7 +145,7 @@ func (c *gettyConn) SetReadTimeout(rTimeout time.Duration) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c gettyConn) writeTimeout() time.Duration {
|
||||
func (c *gettyConn) writeTimeout() time.Duration {
|
||||
return c.wTimeout.Load()
|
||||
}
|
||||
|
||||
@@ -553,7 +551,7 @@ func (w *gettyWSConn) handlePing(message string) error {
|
||||
err := w.writePong([]byte(message))
|
||||
if err == websocket.ErrCloseSent {
|
||||
err = nil
|
||||
} else if e, ok := err.(net.Error); ok && e.Temporary() {
|
||||
} else if e, ok := err.(net.Error); ok && e.Timeout() {
|
||||
err = nil
|
||||
}
|
||||
if err == nil {
|
||||
|
@@ -23,9 +23,9 @@ import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"github.com/eolinker/eosc/log"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -303,7 +303,7 @@ func (s *server) runTCPEventLoop(newSession NewSessionCallback) {
|
||||
}
|
||||
client, err = s.accept(newSession)
|
||||
if err != nil {
|
||||
if netErr, ok := perrors.Cause(err).(net.Error); ok && netErr.Temporary() {
|
||||
if netErr, ok := perrors.Cause(err).(net.Error); ok && netErr.Timeout() {
|
||||
if delay == 0 {
|
||||
delay = 5 * time.Millisecond
|
||||
} else {
|
||||
@@ -456,9 +456,9 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) {
|
||||
}
|
||||
|
||||
if s.caCert != "" {
|
||||
certPem, err = ioutil.ReadFile(s.caCert)
|
||||
certPem, err = os.ReadFile(s.caCert)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err:%+v", s.caCert, perrors.WithStack(err)))
|
||||
panic(fmt.Errorf("os.ReadFile(certFile{%s}) = err:%+v", s.caCert, perrors.WithStack(err)))
|
||||
}
|
||||
certPool = x509.NewCertPool()
|
||||
if ok := certPool.AppendCertsFromPEM(certPem); !ok {
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"github.com/eolinker/eosc/log"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
import (
|
||||
@@ -63,9 +63,9 @@ func (s *ServerTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) {
|
||||
}
|
||||
|
||||
if s.ServerTrustCertCollectionPath != "" {
|
||||
certPem, err = ioutil.ReadFile(s.ServerTrustCertCollectionPath)
|
||||
certPem, err = os.ReadFile(s.ServerTrustCertCollectionPath)
|
||||
if err != nil {
|
||||
log.Error(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err:%+v", s.ServerTrustCertCollectionPath, perrors.WithStack(err)))
|
||||
log.Error(fmt.Errorf("os.ReadFile(certFile{%s}) = err:%+v", s.ServerTrustCertCollectionPath, perrors.WithStack(err)))
|
||||
return nil, err
|
||||
}
|
||||
certPool = x509.NewCertPool()
|
||||
@@ -95,7 +95,7 @@ func (c *ClientTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) {
|
||||
log.Error(fmt.Sprintf("Unable to load X509 Key Pair %v", err))
|
||||
return nil, err
|
||||
}
|
||||
certBytes, err := ioutil.ReadFile(c.ClientTrustCertCollectionPath)
|
||||
certBytes, err := os.ReadFile(c.ClientTrustCertCollectionPath)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("Unable to read pem file: %s", c.ClientTrustCertCollectionPath))
|
||||
return nil, err
|
||||
|
100
go.mod
100
go.mod
@@ -5,6 +5,7 @@ go 1.19
|
||||
require (
|
||||
dubbo.apache.org/dubbo-go/v3 v3.0.5
|
||||
github.com/Shopify/sarama v1.32.0
|
||||
github.com/apache/dubbo-go-hessian2 v1.11.5
|
||||
github.com/brianvoe/gofakeit/v6 v6.20.1
|
||||
github.com/coocood/freecache v1.2.2
|
||||
github.com/dubbogo/gost v1.13.2
|
||||
@@ -12,6 +13,7 @@ require (
|
||||
github.com/fasthttp/websocket v1.5.0
|
||||
github.com/fullstorydev/grpcurl v1.8.7
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/golang/snappy v0.0.4
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/hashicorp/consul/api v1.13.0
|
||||
@@ -19,11 +21,15 @@ require (
|
||||
github.com/jhump/protoreflect v1.14.1
|
||||
github.com/nsqio/go-nsq v1.1.0
|
||||
github.com/ohler55/ojg v1.12.9
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pkg/sftp v1.13.4
|
||||
github.com/prometheus/client_golang v1.12.2
|
||||
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f
|
||||
github.com/soheilhy/cmux v0.1.5
|
||||
github.com/urfave/cli/v2 v2.23.4
|
||||
github.com/valyala/fasthttp v1.42.0
|
||||
go.uber.org/atomic v1.9.0
|
||||
go.uber.org/zap v1.23.0
|
||||
golang.org/x/crypto v0.1.0
|
||||
google.golang.org/grpc v1.51.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
@@ -33,10 +39,26 @@ require (
|
||||
contrib.go.opencensus.io/exporter/prometheus v0.4.1 // indirect
|
||||
github.com/RoaringBitmap/roaring v1.2.3 // indirect
|
||||
github.com/Workiva/go-datastructures v1.0.52 // indirect
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/apache/dubbo-getty v1.4.9-0.20221022181821-4dc6252ce98c // indirect
|
||||
github.com/armon/go-metrics v0.3.9 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bits-and-blooms/bitset v1.2.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/coreos/go-semver v0.3.0 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/creasty/defaults v1.5.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/deepmap/oapi-codegen v1.8.2 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dubbogo/triple v1.2.2-rc2 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/eapache/go-resiliency v1.2.0 // indirect
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
|
||||
github.com/eapache/queue v1.1.0 // indirect
|
||||
github.com/fatih/color v1.9.0 // indirect
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/go-kit/log v0.1.0 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.0 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
@@ -45,51 +67,10 @@ require (
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.11.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/jinzhu/copier v0.3.5 // indirect
|
||||
github.com/k0kubun/pp v3.0.1+incompatible // indirect
|
||||
github.com/knadh/koanf v1.5.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/mschoch/smat v0.2.0 // indirect
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||
github.com/opentracing/opentracing-go v1.2.0 // indirect
|
||||
github.com/pelletier/go-toml v1.7.0 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||
github.com/prometheus/statsd_exporter v0.21.0 // indirect
|
||||
github.com/shirou/gopsutil/v3 v3.22.2 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||
github.com/tklauser/numcpus v0.4.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/apache/dubbo-go-hessian2 v1.11.6
|
||||
github.com/armon/go-metrics v0.3.9 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/coreos/go-semver v0.3.0 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/deepmap/oapi-codegen v1.8.2 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/eapache/go-resiliency v1.2.0 // indirect
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
|
||||
github.com/eapache/queue v1.1.0 // indirect
|
||||
github.com/fatih/color v1.9.0 // indirect
|
||||
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.4
|
||||
github.com/google/btree v1.0.1 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
||||
@@ -106,50 +87,67 @@ require (
|
||||
github.com/jcmturner/gofork v1.0.0 // indirect
|
||||
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
|
||||
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
|
||||
github.com/jinzhu/copier v0.3.5 // indirect
|
||||
github.com/jonboulle/clockwork v0.2.2 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/julienschmidt/httprouter v1.3.0 // indirect
|
||||
github.com/k0kubun/pp v3.0.1+incompatible // indirect
|
||||
github.com/klauspost/compress v1.15.9 // indirect
|
||||
github.com/knadh/koanf v1.5.0 // indirect
|
||||
github.com/kr/fs v0.1.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mschoch/smat v0.2.0 // indirect
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||
github.com/opentracing/opentracing-go v1.2.0 // indirect
|
||||
github.com/pelletier/go-toml v1.7.0 // indirect
|
||||
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.12.2
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/prometheus/statsd_exporter v0.21.0 // indirect
|
||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899 // indirect
|
||||
github.com/shirou/gopsutil/v3 v3.22.2 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||
github.com/tklauser/numcpus v0.4.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.etcd.io/bbolt v1.3.6 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
|
||||
go.etcd.io/etcd/client/v2 v2.305.5 // indirect
|
||||
go.etcd.io/etcd/client/v2 v2.305.7 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.7 // indirect
|
||||
go.etcd.io/etcd/pkg/v3 v3.5.5 // indirect
|
||||
go.etcd.io/etcd/raft/v3 v3.5.5 // indirect
|
||||
go.etcd.io/etcd/server/v3 v3.5.5 // indirect
|
||||
go.etcd.io/etcd/pkg/v3 v3.5.7 // indirect
|
||||
go.etcd.io/etcd/raft/v3 v3.5.7 // indirect
|
||||
go.etcd.io/etcd/server/v3 v3.5.7 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.25.0 // indirect
|
||||
go.opentelemetry.io/otel v1.11.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.11.0 // indirect
|
||||
go.uber.org/atomic v1.9.0
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/zap v1.23.0
|
||||
golang.org/x/net v0.5.0 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72 // indirect
|
||||
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/eolinker/eosc => ../eosc
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
//MaxBuffer buffer最大值
|
||||
// MaxBuffer buffer最大值
|
||||
const MaxBuffer = 1024 * 500
|
||||
|
||||
var (
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
//FileWriterByPeriod 文件周期写入
|
||||
// FileWriterByPeriod 文件周期写入
|
||||
type FileWriterByPeriod struct {
|
||||
wC chan *bytes.Buffer
|
||||
|
||||
@@ -32,7 +32,7 @@ type FileWriterByPeriod struct {
|
||||
resetChan chan FileController
|
||||
}
|
||||
|
||||
//NewFileWriteByPeriod 获取新的FileWriterByPeriod
|
||||
// NewFileWriteByPeriod 获取新的FileWriterByPeriod
|
||||
func NewFileWriteByPeriod(cfg *Config) *FileWriterByPeriod {
|
||||
w := &FileWriterByPeriod{
|
||||
locker: sync.RWMutex{},
|
||||
@@ -59,7 +59,7 @@ func (w *FileWriterByPeriod) Reset(cfg *Config) {
|
||||
}
|
||||
}
|
||||
|
||||
//Open 打开
|
||||
// Open 打开
|
||||
func (w *FileWriterByPeriod) Open(config *FileController) {
|
||||
w.locker.Lock()
|
||||
defer w.locker.Unlock()
|
||||
@@ -80,7 +80,7 @@ func (w *FileWriterByPeriod) Open(config *FileController) {
|
||||
}()
|
||||
}
|
||||
|
||||
//Close 关闭
|
||||
// Close 关闭
|
||||
func (w *FileWriterByPeriod) Close() {
|
||||
|
||||
isClose := false
|
||||
@@ -210,7 +210,7 @@ func (w *FileWriterByPeriod) do(ctx context.Context, config *FileController) {
|
||||
}
|
||||
|
||||
func (w *FileController) initFile() {
|
||||
err := os.MkdirAll(w.dir, 0755)
|
||||
err := os.MkdirAll(w.dir, 0666)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/eolinker/eosc/log"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
@@ -113,7 +113,7 @@ func (h *_HttpWriter) send(method, url string, header http.Header, p []byte) {
|
||||
return
|
||||
}
|
||||
if response.StatusCode != 200 {
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
body, err := io.ReadAll(response.Body)
|
||||
response.Body.Close()
|
||||
if err != nil {
|
||||
log.DebugF("send to httplog error:%s %s status<%d,%s> :%s\n", method, url, response.StatusCode, response.Status, err.Error())
|
||||
|
@@ -2,10 +2,10 @@ package utils
|
||||
|
||||
import "os"
|
||||
|
||||
//GenFile 根据路径和数据生成文件
|
||||
// GenFile 根据路径和数据生成文件
|
||||
func GenFile(dir, fileName, data string) error {
|
||||
dir = "work/export/" + dir
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
//ConvertIntArrayToString 转换整型数组
|
||||
// ConvertIntArrayToString 转换整型数组
|
||||
func ConvertIntArrayToString(ids []int) string {
|
||||
idLen := len(ids)
|
||||
if idLen < 1 {
|
||||
@@ -32,7 +32,7 @@ func ConvertIntArrayToString(ids []int) string {
|
||||
return idStr
|
||||
}
|
||||
|
||||
//ConvertArray 将[]string转为[]int
|
||||
// ConvertArray 将[]string转为[]int
|
||||
func ConvertArray(arr []string) (bool, []int) {
|
||||
result := make([]int, 0)
|
||||
for _, i := range arr {
|
||||
@@ -45,7 +45,7 @@ func ConvertArray(arr []string) (bool, []int) {
|
||||
return true, result
|
||||
}
|
||||
|
||||
//ValidateRemoteAddr 判断ip端口是否合法
|
||||
// ValidateRemoteAddr 判断ip端口是否合法
|
||||
func ValidateRemoteAddr(ip string) bool {
|
||||
match, err := regexp.MatchString(`^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))\:(([0-9])|([1-9][0-9]{1,3})|([1-6][0-9]{0,4}))$`, ip)
|
||||
if err != nil {
|
||||
@@ -54,7 +54,7 @@ func ValidateRemoteAddr(ip string) bool {
|
||||
return match
|
||||
}
|
||||
|
||||
//ValidateURL 判断ip端口是否合法
|
||||
// ValidateURL 判断ip端口是否合法
|
||||
func ValidateURL(url string) bool {
|
||||
match, err := regexp.MatchString(`^/(([a-zA-Z][0-9a-zA-Z+\-\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\.\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\.\-_!~*'()%]+)?$`, url)
|
||||
if err != nil {
|
||||
@@ -63,7 +63,7 @@ func ValidateURL(url string) bool {
|
||||
return match
|
||||
}
|
||||
|
||||
//Intercept 获取IP
|
||||
// Intercept 获取IP
|
||||
func Intercept(str, substr string) (string, string) {
|
||||
result := strings.Index(str, substr)
|
||||
var rs string
|
||||
@@ -78,14 +78,14 @@ func Intercept(str, substr string) (string, string) {
|
||||
return rs, bs
|
||||
}
|
||||
|
||||
//Md5 md5加密
|
||||
// Md5 md5加密
|
||||
func Md5(encodeString string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(encodeString))
|
||||
return hex.EncodeToString(h.Sum(nil)) // 输出加密结果
|
||||
}
|
||||
|
||||
//GetRandomStringBack 生成随机字符串
|
||||
// GetRandomStringBack 生成随机字符串
|
||||
func GetRandomStringBack(num int) string {
|
||||
str := "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"
|
||||
bytes := []byte(str)
|
||||
@@ -101,9 +101,10 @@ var (
|
||||
randManager = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
randBytes = []byte("123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ")
|
||||
randSize = len(randBytes)
|
||||
reg, _ = regexp.Compile(`[0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f]`)
|
||||
)
|
||||
|
||||
//GetRandomString 生成随机字符串
|
||||
// GetRandomString 生成随机字符串
|
||||
func GetRandomString(num int) string {
|
||||
result := make([]byte, num)
|
||||
for i := 0; i < num; i++ {
|
||||
@@ -112,7 +113,7 @@ func GetRandomString(num int) string {
|
||||
return string(result)
|
||||
}
|
||||
|
||||
//CheckFileIsExist 判断文件是否存在 存在返回 true 不存在返回false
|
||||
// CheckFileIsExist 判断文件是否存在 存在返回 true 不存在返回false
|
||||
func CheckFileIsExist(filename string) bool {
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
return false
|
||||
@@ -120,7 +121,7 @@ func CheckFileIsExist(filename string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
//Stop 关闭网关服务,重启读取配置文件
|
||||
// Stop 关闭网关服务,重启读取配置文件
|
||||
func Stop() bool {
|
||||
id := os.Getpid()
|
||||
cmd := exec.Command("/bin/bash", "-c", "kill -HUP "+strconv.Itoa(id))
|
||||
@@ -130,19 +131,18 @@ func Stop() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
//GetMac 获取MAC地址
|
||||
// GetMac 获取MAC地址
|
||||
func GetMac() (bool, string) {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return false, "Poor soul, here is what you got: " + err.Error()
|
||||
}
|
||||
|
||||
for _, inter := range interfaces {
|
||||
mac := inter.HardwareAddr //获取本机MAC地址
|
||||
m := fmt.Sprintf("%s", mac)
|
||||
match, err := regexp.MatchString(`[0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f]`, m)
|
||||
if err != nil {
|
||||
return false, ""
|
||||
}
|
||||
match := reg.MatchString(m)
|
||||
|
||||
if match {
|
||||
return true, string(m)
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func GetMac() (bool, string) {
|
||||
return false, ""
|
||||
}
|
||||
|
||||
//GzipCompress 转成Gzip
|
||||
// GzipCompress 转成Gzip
|
||||
func GzipCompress(origin []byte) ([]byte, error) {
|
||||
var b bytes.Buffer
|
||||
gz := gzip.NewWriter(&b)
|
||||
|
Reference in New Issue
Block a user