diff --git a/agent/input/discord/conn.go b/agent/input/discord/conn.go index 20a35af9..cadc69d0 100644 --- a/agent/input/discord/conn.go +++ b/agent/input/discord/conn.go @@ -7,7 +7,7 @@ import ( "github.com/bwmarrin/discordgo" "github.com/micro/go-micro/agent/input" - "github.com/micro/go-log" + "github.com/micro/go-micro/util/log" ) type discordConn struct { diff --git a/agent/input/telegram/conn.go b/agent/input/telegram/conn.go index 99311f4c..44d1ada1 100644 --- a/agent/input/telegram/conn.go +++ b/agent/input/telegram/conn.go @@ -7,7 +7,7 @@ import ( "github.com/forestgiant/sliceutil" "github.com/micro/go-micro/agent/input" - "github.com/micro/go-log" + "github.com/micro/go-micro/util/log" "gopkg.in/telegram-bot-api.v4" ) diff --git a/agent/proto/bot.micro.go b/agent/proto/bot.micro.go index 2bac4842..0a027a82 100644 --- a/agent/proto/bot.micro.go +++ b/agent/proto/bot.micro.go @@ -20,9 +20,9 @@ import fmt "fmt" import math "math" import ( + context "context" client "github.com/micro/go-micro/client" server "github.com/micro/go-micro/server" - context "context" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/broker/http_broker_test.go b/broker/http_broker_test.go index a2aabdd5..69bad10e 100644 --- a/broker/http_broker_test.go +++ b/broker/http_broker_test.go @@ -7,8 +7,8 @@ import ( glog "github.com/go-log/log" "github.com/google/uuid" - "github.com/micro/go-log" "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/util/log" ) func newTestRegistry() *memory.Registry { diff --git a/cmd/cmd.go b/cmd/cmd.go index c4987dbf..9a9a34ef 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -10,9 +10,9 @@ import ( "time" "github.com/micro/cli" - "github.com/micro/go-log" "github.com/micro/go-micro/client" "github.com/micro/go-micro/server" + "github.com/micro/go-micro/util/log" // brokers "github.com/micro/go-micro/broker" diff --git a/codec/text/text.go b/codec/text/text.go new file mode 100644 index 00000000..f6f28859 --- /dev/null +++ b/codec/text/text.go @@ -0,0 +1,75 @@ +// Package text reads any text/* content-type +package text + +import ( + "fmt" + "io" + "io/ioutil" + + "github.com/micro/go-micro/codec" +) + +type Codec struct { + Conn io.ReadWriteCloser +} + +// Frame gives us the ability to define raw data to send over the pipes +type Frame struct { + Data []byte +} + +func (c *Codec) ReadHeader(m *codec.Message, t codec.MessageType) error { + return nil +} + +func (c *Codec) ReadBody(b interface{}) error { + // read bytes + buf, err := ioutil.ReadAll(c.Conn) + if err != nil { + return err + } + + switch b.(type) { + case *[]byte: + v := b.(*[]byte) + *v = buf + case *Frame: + v := b.(*Frame) + v.Data = buf + default: + return fmt.Errorf("failed to read body: %v is not type of *[]byte", b) + } + + return nil +} + +func (c *Codec) Write(m *codec.Message, b interface{}) error { + var v []byte + switch b.(type) { + case *Frame: + v = b.(*Frame).Data + case *[]byte: + ve := b.(*[]byte) + v = *ve + case []byte: + v = b.([]byte) + default: + return fmt.Errorf("failed to write: %v is not type of *[]byte or []byte", b) + } + _, err := c.Conn.Write(v) + return err +} + +func (c *Codec) Close() error { + return c.Conn.Close() +} + +func (c *Codec) String() string { + return "bytes" +} + +func NewCodec(c io.ReadWriteCloser) codec.Codec { + return &Codec{ + Conn: c, + } +} diff --git a/go.mod b/go.mod index 45392aef..56a83819 100644 --- a/go.mod +++ b/go.mod @@ -122,7 +122,7 @@ require ( github.com/mholt/certmagic v0.5.1 // indirect github.com/michaelklishin/rabbit-hole v1.5.0 // indirect github.com/micro/cli v0.2.0 - github.com/micro/go-log v0.1.0 + github.com/micro/go-micro/util/log v0.1.0 github.com/micro/go-rcache v0.3.0 github.com/micro/mdns v0.1.0 github.com/micro/util v0.2.0 diff --git a/go.sum b/go.sum index 7e47ccd2..90b692dd 100644 --- a/go.sum +++ b/go.sum @@ -675,8 +675,8 @@ github.com/micro/cli v0.1.0 h1:5DT+QdbAPPQvB3gYTgwze7tFO1m+7DU1sz9XfQczbsc= github.com/micro/cli v0.1.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= -github.com/micro/go-log v0.1.0 h1:szYSR+yyTsomZM2jyinJC5562DlqffSjHmTZFaeZ2vY= -github.com/micro/go-log v0.1.0/go.mod h1:qaFBF6d6Jk01Gz4cbMkCA2vVuLk3FSaLLjmEGrMCreA= +github.com/micro/go-micro/util/log v0.1.0 h1:szYSR+yyTsomZM2jyinJC5562DlqffSjHmTZFaeZ2vY= +github.com/micro/go-micro/util/log v0.1.0/go.mod h1:qaFBF6d6Jk01Gz4cbMkCA2vVuLk3FSaLLjmEGrMCreA= github.com/micro/go-micro v0.23.0/go.mod h1:3z3lfMkNU9Sr1L/CxL++8pVJmQapRo0N6kNjwYDtOVs= github.com/micro/go-micro v0.26.0/go.mod h1:CweCFO/pq8dCSIOdzVZ4ooIpUrKlyJ0AcFB269M7PgU= github.com/micro/go-micro v0.26.1/go.mod h1:Jgc5gPEmDiG1TWE5Qnzzx5qyXnU9VTXKT1FkXkfvt8g= diff --git a/registry/cache/rcache.go b/registry/cache/rcache.go index 53b11576..09ff3c48 100644 --- a/registry/cache/rcache.go +++ b/registry/cache/rcache.go @@ -7,8 +7,8 @@ import ( "sync" "time" - log "github.com/micro/go-log" "github.com/micro/go-micro/registry" + log "github.com/micro/go-micro/util/log" ) // Cache is the registry cache interface diff --git a/registry/gossip/gossip.go b/registry/gossip/gossip.go index ca654568..c8ea457a 100644 --- a/registry/gossip/gossip.go +++ b/registry/gossip/gossip.go @@ -16,9 +16,9 @@ import ( "github.com/golang/protobuf/proto" "github.com/google/uuid" "github.com/hashicorp/memberlist" - log "github.com/micro/go-log" "github.com/micro/go-micro/registry" pb "github.com/micro/go-micro/registry/gossip/proto" + log "github.com/micro/go-micro/util/log" "github.com/mitchellh/hashstructure" ) diff --git a/runtime/package/docker/docker.go b/runtime/package/docker/docker.go index 4a420060..2f0c46c0 100644 --- a/runtime/package/docker/docker.go +++ b/runtime/package/docker/docker.go @@ -9,8 +9,8 @@ import ( "path/filepath" "github.com/fsouza/go-dockerclient" - "github.com/micro/go-log" "github.com/micro/go-micro/runtime/package" + "github.com/micro/go-micro/util/log" ) type Packager struct { diff --git a/server/rpc_router.go b/server/rpc_router.go index 5d23d5b8..af29d4b8 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -16,8 +16,8 @@ import ( "unicode" "unicode/utf8" - "github.com/micro/go-log" "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/util/log" ) var ( diff --git a/server/rpc_server.go b/server/rpc_server.go index 6838d65e..bd95a312 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -10,13 +10,13 @@ import ( "sync" "time" - log "github.com/micro/go-log" "github.com/micro/go-micro/broker" "github.com/micro/go-micro/codec" "github.com/micro/go-micro/metadata" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/transport" "github.com/micro/go-micro/util/addr" + log "github.com/micro/go-micro/util/log" ) type rpcServer struct { diff --git a/server/server.go b/server/server.go index 706e6b7e..2e742f95 100644 --- a/server/server.go +++ b/server/server.go @@ -8,9 +8,9 @@ import ( "syscall" "github.com/google/uuid" - log "github.com/micro/go-log" "github.com/micro/go-micro/codec" "github.com/micro/go-micro/registry" + log "github.com/micro/go-micro/util/log" ) // Server is a simple micro server abstraction diff --git a/service_test.go b/service_test.go index 5c2dba3f..6d4cbbc0 100644 --- a/service_test.go +++ b/service_test.go @@ -7,10 +7,10 @@ import ( "testing" glog "github.com/go-log/log" - "github.com/micro/go-log" "github.com/micro/go-micro/client" "github.com/micro/go-micro/registry/memory" proto "github.com/micro/go-micro/server/debug/proto" + "github.com/micro/go-micro/util/log" ) func testShutdown(wg *sync.WaitGroup, cancel func()) { diff --git a/util/log/README.md b/util/log/README.md index 2ae61058..6e26ad79 100644 --- a/util/log/README.md +++ b/util/log/README.md @@ -9,7 +9,7 @@ It defaults the logger to the stdlib log implementation. Set the logger for micro libraries ```go -// import micro/go-log +// import go-micro/util/log import "github.com/micro/go-micro/util/log" // SetLogger expects github.com/go-log/log.Logger interface