Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
959901fcad | ||
|
|
83c1e36469 |
8
cache/cache.go
vendored
8
cache/cache.go
vendored
@@ -1,14 +1,14 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
|
||||||
"github.com/creachadair/cityhash"
|
"github.com/creachadair/cityhash"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//API
|
// API
|
||||||
var Nil error = errors.New("cache: nil")
|
var Nil error = errors.New("cache: nil")
|
||||||
|
|
||||||
func Set(key string, value interface{}) error {
|
func Set(key string, value interface{}) error {
|
||||||
@@ -27,7 +27,7 @@ func Del(key string) error {
|
|||||||
return del(key)
|
return del(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
//internal
|
// internal
|
||||||
var dbs map[byte]*db
|
var dbs map[byte]*db
|
||||||
|
|
||||||
type db struct {
|
type db struct {
|
||||||
@@ -59,7 +59,7 @@ func newdb(t time.Duration) *db {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
//定期扫描过期的key
|
// 定期扫描过期的key
|
||||||
func (this *db) flush() {
|
func (this *db) flush() {
|
||||||
for range time.NewTicker(this.t).C {
|
for range time.NewTicker(this.t).C {
|
||||||
this.doflush()
|
this.doflush()
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package gfetcd
|
package gfetcd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
|
|
||||||
"github.com/coreos/etcd/clientv3"
|
"github.com/coreos/etcd/clientv3"
|
||||||
etcdnaming "github.com/coreos/etcd/clientv3/naming"
|
etcdnaming "github.com/coreos/etcd/clientv3/naming"
|
||||||
@@ -31,7 +31,7 @@ func (self *NameConfig) GetAddr() string {
|
|||||||
return self.Addr
|
return self.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取本机的内网Ip, 如果发现对方的ip 和自己的ip 相同,用127.0.0.1 替代
|
// 获取本机的内网Ip, 如果发现对方的ip 和自己的ip 相同,用127.0.0.1 替代
|
||||||
func getLocalIP() string {
|
func getLocalIP() string {
|
||||||
ifaces, _ := net.Interfaces()
|
ifaces, _ := net.Interfaces()
|
||||||
for _, i := range ifaces {
|
for _, i := range ifaces {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/MAN00K/unitech_golib
|
module code.infininov.com/Infini/unitech-golib
|
||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
|
|
||||||
"github.com/Shopify/sarama"
|
"github.com/Shopify/sarama"
|
||||||
cluster "github.com/bsm/sarama-cluster"
|
cluster "github.com/bsm/sarama-cluster"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package lrucache
|
package lrucache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
|
||||||
"github.com/creachadair/cityhash"
|
"github.com/creachadair/cityhash"
|
||||||
"github.com/hashicorp/golang-lru"
|
"github.com/hashicorp/golang-lru"
|
||||||
"time"
|
"time"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/metric"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MAN00K/unitech_golib/metric"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/metric"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MAN00K/unitech_golib/metric"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
consulapi "github.com/hashicorp/consul/api"
|
consulapi "github.com/hashicorp/consul/api"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/metrics"
|
||||||
|
"code.infininov.com/Infini/unitech-golib/metrics/prometheus"
|
||||||
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/MAN00K/unitech_golib/metrics"
|
|
||||||
"github.com/MAN00K/unitech_golib/metrics/prometheus"
|
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package prometheus
|
package prometheus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/MAN00K/unitech_golib/metrics"
|
"code.infininov.com/Infini/unitech-golib/metrics"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package prometheus
|
package prometheus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/metrics"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MAN00K/unitech_golib/metrics"
|
|
||||||
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|||||||
10
qgrpc/op.go
10
qgrpc/op.go
@@ -1,10 +1,10 @@
|
|||||||
package qgrpc
|
package qgrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/qgrpc/ping"
|
||||||
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MAN00K/unitech_golib/qgrpc/ping"
|
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
|
||||||
"github.com/coreos/etcd/clientv3"
|
"github.com/coreos/etcd/clientv3"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/keepalive"
|
"google.golang.org/grpc/keepalive"
|
||||||
@@ -87,7 +87,7 @@ func NewClient(cfg *ClientConfig) (client *Client, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//user.User|127.0.0.1:9011 -> Server{Name: user.User Addrs: []string{127.0.0.1:9011}}
|
// user.User|127.0.0.1:9011 -> Server{Name: user.User Addrs: []string{127.0.0.1:9011}}
|
||||||
func ParseServerName(serverName string) *RpcServer {
|
func ParseServerName(serverName string) *RpcServer {
|
||||||
ss := strings.Split(serverName, "|")
|
ss := strings.Split(serverName, "|")
|
||||||
s := &RpcServer{Name: ss[0]}
|
s := &RpcServer{Name: ss[0]}
|
||||||
@@ -101,12 +101,12 @@ func ParseServerName(serverName string) *RpcServer {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
//根据server-name 获得对应的连接池
|
// 根据server-name 获得对应的连接池
|
||||||
func (self *Client) GetConn(serverName string) *grpc.ClientConn {
|
func (self *Client) GetConn(serverName string) *grpc.ClientConn {
|
||||||
return self.rpcServers[serverName]
|
return self.rpcServers[serverName]
|
||||||
}
|
}
|
||||||
|
|
||||||
//从etcd注销
|
// 从etcd注销
|
||||||
func (self *Server) Revoke() error {
|
func (self *Server) Revoke() error {
|
||||||
_, err := self.etcdCli.Revoke(context.Background(), self.etcdId)
|
_, err := self.etcdCli.Revoke(context.Background(), self.etcdId)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package qgrpc
|
package qgrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.infininov.com/Infini/unitech-golib/tlog"
|
||||||
"context"
|
"context"
|
||||||
"github.com/MAN00K/unitech_golib/tlog"
|
|
||||||
"github.com/coreos/etcd/clientv3"
|
"github.com/coreos/etcd/clientv3"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|||||||
Reference in New Issue
Block a user