Skip to content

Commit

Permalink
Rename hiroyaonoe/bcop-go into picop-rd/picop-go
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroyaonoe committed Mar 29, 2023
1 parent ccd8403 commit a9a0ec3
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 85 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# bcop-go
BCoP Go実装
# picop-go
PiCoP Implementation for Go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package bcopmysql
package picopmysql

import (
"context"
"net"

"github.com/go-sql-driver/mysql"
bcopprop "github.com/hiroyaonoe/bcop-go/propagation"
"github.com/hiroyaonoe/bcop-go/protocol/header"
bcopnet "github.com/hiroyaonoe/bcop-go/protocol/net"
picopprop "github.com/picop-rd/picop-go/propagation"
"github.com/picop-rd/picop-go/protocol/header"
picopnet "github.com/picop-rd/picop-go/protocol/net"
otelprop "go.opentelemetry.io/otel/propagation"
)

Expand All @@ -28,9 +28,9 @@ func DialContext(netP string, propagator otelprop.TextMapPropagator) mysql.DialC
}

h := header.NewV1()
propagator.Inject(ctx, bcopprop.NewBCoPCarrier(h))
propagator.Inject(ctx, picopprop.NewPiCoPCarrier(h))

bconn := bcopnet.SenderConn(conn, h)
bconn := picopnet.SenderConn(conn, h)
err = bconn.WriteHeader()
if err != nil {
return nil, err
Expand Down
19 changes: 0 additions & 19 deletions contrib/net/http/bcophttp/server.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package bcophttp
package picophttp

import (
"net/http"

bcopprop "github.com/hiroyaonoe/bcop-go/propagation"
"github.com/hiroyaonoe/bcop-go/protocol/header"
picopprop "github.com/picop-rd/picop-go/propagation"
"github.com/picop-rd/picop-go/protocol/header"
otelprop "go.opentelemetry.io/otel/propagation"
)

Expand All @@ -24,8 +24,8 @@ func NewHandler(hl http.Handler, prop otelprop.TextMapPropagator) Handler {

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
hd := ctx.Value(BCoPHeaderContextKey).(*header.Header)
ctx = h.propagator.Extract(ctx, bcopprop.NewBCoPCarrier(hd))
hd := ctx.Value(PiCoPHeaderContextKey).(*header.Header)
ctx = h.propagator.Extract(ctx, picopprop.NewPiCoPCarrier(hd))
nr := r.Clone(ctx)

h.Handler.ServeHTTP(w, nr)
Expand Down
19 changes: 19 additions & 0 deletions contrib/net/http/picophttp/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package picophttp

import (
"context"
"net"

picopnet "github.com/picop-rd/picop-go/protocol/net"
)

type piCoPHeaderContextKeyType int

const PiCoPHeaderContextKey piCoPHeaderContextKeyType = iota

func ConnContext(ctx context.Context, c net.Conn) context.Context {
if bc, ok := c.(*picopnet.Conn); ok {
ctx = context.WithValue(ctx, PiCoPHeaderContextKey, bc.Header)
}
return ctx
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package bcophttp
package picophttp

import (
"context"
"net"
"net/http"

bcopprop "github.com/hiroyaonoe/bcop-go/propagation"
"github.com/hiroyaonoe/bcop-go/protocol/header"
bcopnet "github.com/hiroyaonoe/bcop-go/protocol/net"
picopprop "github.com/picop-rd/picop-go/propagation"
"github.com/picop-rd/picop-go/protocol/header"
picopnet "github.com/picop-rd/picop-go/protocol/net"
otelprop "go.opentelemetry.io/otel/propagation"
)

Expand Down Expand Up @@ -45,9 +45,9 @@ func wrapDialContext(dc func(ctx context.Context, network, addr string) (net.Con
}

h := header.NewV1()
propagator.Inject(ctx, bcopprop.NewBCoPCarrier(h))
propagator.Inject(ctx, picopprop.NewPiCoPCarrier(h))

bconn := bcopnet.SenderConn(conn, h)
bconn := picopnet.SenderConn(conn, h)
return bconn, err
}
}
10 changes: 5 additions & 5 deletions example/http-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"net/http"
"os"

"github.com/hiroyaonoe/bcop-go/contrib/net/http/bcophttp"
"github.com/hiroyaonoe/bcop-go/propagation"
"github.com/hiroyaonoe/bcop-go/protocol/header"
"github.com/picop-rd/picop-go/contrib/net/http/picophttp"
"github.com/picop-rd/picop-go/propagation"
"github.com/picop-rd/picop-go/protocol/header"
)

func main() {
Expand All @@ -19,10 +19,10 @@ func main() {
// 伝播されたContextを用意
h := header.NewV1()
h.Set(propagation.EnvIDHeader, "aaaaa")
ctx := propagation.EnvID{}.Extract(context.Background(), propagation.NewBCoPCarrier(h))
ctx := propagation.EnvID{}.Extract(context.Background(), propagation.NewPiCoPCarrier(h))

client := &http.Client{
Transport: bcophttp.NewTransport(nil, propagation.EnvID{}),
Transport: picophttp.NewTransport(nil, propagation.EnvID{}),
}

req, err := http.NewRequestWithContext(ctx, "GET", "http://localhost:"+*port, nil)
Expand Down
18 changes: 9 additions & 9 deletions example/http-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"net"
"net/http"

"github.com/hiroyaonoe/bcop-go/contrib/net/http/bcophttp"
"github.com/hiroyaonoe/bcop-go/propagation"
"github.com/hiroyaonoe/bcop-go/protocol/header"
bcopnet "github.com/hiroyaonoe/bcop-go/protocol/net"
"github.com/picop-rd/picop-go/contrib/net/http/picophttp"
"github.com/picop-rd/picop-go/propagation"
"github.com/picop-rd/picop-go/protocol/header"
picopnet "github.com/picop-rd/picop-go/protocol/net"
)

func main() {
Expand All @@ -22,24 +22,24 @@ func main() {

server := &http.Server{
Addr: ":" + *port,
Handler: bcophttp.NewHandler(http.DefaultServeMux, propagation.EnvID{}),
ConnContext: bcophttp.ConnContext,
Handler: picophttp.NewHandler(http.DefaultServeMux, propagation.EnvID{}),
ConnContext: picophttp.ConnContext,
}

ln, err := net.Listen("tcp", server.Addr)
if err != nil {
log.Fatal(err)
}

bln := bcopnet.NewListener(ln)
bln := picopnet.NewListener(ln)

log.Fatal(server.Serve(bln))
}

func handler(w http.ResponseWriter, r *http.Request) {
// 伝播されたContextを確認
h := header.NewV1()
propagation.EnvID{}.Inject(r.Context(), propagation.NewBCoPCarrier(h))
propagation.EnvID{}.Inject(r.Context(), propagation.NewPiCoPCarrier(h))
w.WriteHeader(http.StatusOK)
io.WriteString(w, fmt.Sprintf("BCoP Header Accepted: %s\n", h))
io.WriteString(w, fmt.Sprintf("PiCoP Header Accepted: %s\n", h))
}
12 changes: 6 additions & 6 deletions example/mysql-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"fmt"
"log"

// _ "github.com/go-sql-driver/mysql" bcopmysql内でimportされるので不要
"github.com/hiroyaonoe/bcop-go/contrib/github.com/go-sql-driver/mysql/bcopmysql"
"github.com/hiroyaonoe/bcop-go/propagation"
"github.com/hiroyaonoe/bcop-go/protocol/header"
// _ "github.com/go-sql-driver/mysql" picopmysql内でimportされるので不要
"github.com/picop-rd/picop-go/contrib/github.com/go-sql-driver/mysql/picopmysql"
"github.com/picop-rd/picop-go/propagation"
"github.com/picop-rd/picop-go/protocol/header"
)

func main() {
// 伝播されたContextを用意
h := header.NewV1()
h.Set(propagation.EnvIDHeader, "aaaaa")
ctx := propagation.EnvID{}.Extract(context.Background(), propagation.NewBCoPCarrier(h))
ctx := propagation.EnvID{}.Extract(context.Background(), propagation.NewPiCoPCarrier(h))

bcopmysql.RegisterDialContext("tcp", propagation.EnvID{})
picopmysql.RegisterDialContext("tcp", propagation.EnvID{})

db, err := sql.Open("mysql", "root:@tcp(localhost:9000)/test")
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions example/tcp-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"net"
"os"

"github.com/hiroyaonoe/bcop-go/propagation"
"github.com/hiroyaonoe/bcop-go/protocol/header"
bcopnet "github.com/hiroyaonoe/bcop-go/protocol/net"
"github.com/picop-rd/picop-go/propagation"
"github.com/picop-rd/picop-go/protocol/header"
picopnet "github.com/picop-rd/picop-go/protocol/net"
"golang.org/x/sync/errgroup"
)

Expand All @@ -29,7 +29,7 @@ func main() {

h := header.NewV1()
h.Set(propagation.EnvIDHeader, "aaaaa")
bconn := bcopnet.SenderConn(conn, h)
bconn := picopnet.SenderConn(conn, h)

var eg errgroup.Group

Expand Down
8 changes: 4 additions & 4 deletions example/tcp-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net"
"os"

bcopnet "github.com/hiroyaonoe/bcop-go/protocol/net"
picopnet "github.com/picop-rd/picop-go/protocol/net"
"golang.org/x/sync/errgroup"
)

Expand All @@ -22,9 +22,9 @@ func main() {
log.Fatalf(err.Error())
}

bln := bcopnet.NewListener(ln)
bln := picopnet.NewListener(ln)

bconn, err := bln.AcceptWithBCoPConn()
bconn, err := bln.AcceptWithPiCoPConn()
if err != nil {
log.Fatalf(err.Error())
}
Expand All @@ -34,7 +34,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
fmt.Printf("BCoP Header Accepted: %s\n", header)
fmt.Printf("PiCoP Header Accepted: %s\n", header)

var eg errgroup.Group

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/hiroyaonoe/bcop-go
module github.com/picop-rd/picop-go

go 1.18

Expand Down
18 changes: 9 additions & 9 deletions propagation/carrier.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package propagation

import (
"github.com/hiroyaonoe/bcop-go/protocol/header"
"github.com/picop-rd/picop-go/protocol/header"
"go.opentelemetry.io/otel/propagation"
)

// BCoPCarrier adapts BCoP to satisfy the OpenTelemetry TextMapCarrier interface.
type BCoPCarrier struct {
// PiCoPCarrier adapts PiCoP to satisfy the OpenTelemetry TextMapCarrier interface.
type PiCoPCarrier struct {
*header.Header
}

var _ propagation.TextMapCarrier = BCoPCarrier{}
var _ propagation.TextMapCarrier = PiCoPCarrier{}

func NewBCoPCarrier(h *header.Header) BCoPCarrier {
return BCoPCarrier{h}
func NewPiCoPCarrier(h *header.Header) PiCoPCarrier {
return PiCoPCarrier{h}
}

func (bc BCoPCarrier) Get(key string) string {
func (bc PiCoPCarrier) Get(key string) string {
return bc.Header.Get(key)
}

func (bc BCoPCarrier) Set(key, value string) {
func (bc PiCoPCarrier) Set(key, value string) {
bc.Header.Set(key, value)
return
}

func (bc BCoPCarrier) Keys() []string {
func (bc PiCoPCarrier) Keys() []string {
return bc.Header.Keys()
}
12 changes: 6 additions & 6 deletions protocol/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
var (
SignatureV1 = []byte{'\x0D', '\x0A', '\x0D', '\x0A', '\x00', '\x0D', '\x0A', '\x51', '\x55', '\x49', '\x54', '\x0A', '\x01'}

ErrNoBCoP = errors.New("BCoP: signature not present")
ErrCannotReadV1Header = errors.New("BCoP: cannot read v1 header")
ErrNoPiCoP = errors.New("PiCoP: signature not present")
ErrCannotReadV1Header = errors.New("PiCoP: cannot read v1 header")
)

type Header struct {
version byte
value MIMEHeader
}

// NewV1 return BCoP V1 Header.
// NewV1 return PiCoP V1 Header.
func NewV1() *Header {
return &Header{
version: 1,
Expand Down Expand Up @@ -57,7 +57,7 @@ func (h Header) Keys() []string {
}

func (h Header) String() string {
return fmt.Sprintf("BCoP Header{ version: %d, value: %s }", h.version, h.value.String())
return fmt.Sprintf("PiCoP Header{ version: %d, value: %s }", h.version, h.value.String())
}

func (h Header) Format() []byte {
Expand All @@ -77,15 +77,15 @@ func Parse(r io.Reader) (*Header, error) {
_, err := r.Read(sign)
if err != nil {
if err == io.EOF {
return nil, ErrNoBCoP
return nil, ErrNoPiCoP
}
return nil, err
}

if bytes.Equal(sign, SignatureV1) {
return parseV1(r)
}
return nil, ErrNoBCoP
return nil, ErrNoPiCoP
}

func parseV1(r io.Reader) (*Header, error) {
Expand Down
2 changes: 1 addition & 1 deletion protocol/net/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net"
"sync"

"github.com/hiroyaonoe/bcop-go/protocol/header"
"github.com/picop-rd/picop-go/protocol/header"
)

type connType int
Expand Down
4 changes: 2 additions & 2 deletions protocol/net/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ net.Listener = Listener{}
func NewListener(l net.Listener) Listener {
return Listener{l}
}
func (l Listener) AcceptWithBCoPConn() (*Conn, error) {
func (l Listener) AcceptWithPiCoPConn() (*Conn, error) {
conn, err := l.Listener.Accept()
if err != nil {
return nil, err
Expand All @@ -29,5 +29,5 @@ func (l Listener) AcceptWithBCoPConn() (*Conn, error) {
}

func (l Listener) Accept() (net.Conn, error) {
return l.AcceptWithBCoPConn()
return l.AcceptWithPiCoPConn()
}

0 comments on commit a9a0ec3

Please sign in to comment.