Skip to content

Commit f1054b7

Browse files
committed
Add English comments
1 parent a9a0ec3 commit f1054b7

File tree

11 files changed

+30
-20
lines changed

11 files changed

+30
-20
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# picop-go
2-
PiCoP Implementation for Go
2+
PiCoP Protocol Library for Go
3+
4+
## Description
5+
This repository provide Go library for communicating with PiCoP Protocol.
6+
7+
## Support
8+
- `net`([`protocol/net`](./protocol/net`))
9+
- `net/http`([`contrib/net/http/picophttp`](./contrib/net/http/picophttp))
10+
- `github.com/go-sql-driver/mysql`([`contrib/github.com/go-sql-griver/mysql/picopmysql`](./contrib/github.com/go-sql-driver/mysql/picopmysql))
11+
12+
You can refer to [`example`](./example) directory for usage.

contrib/github.com/go-sql-driver/mysql/picopmysql/dial.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import (
1111
otelprop "go.opentelemetry.io/otel/propagation"
1212
)
1313

14-
//TODO: propagatorが固定できる場合はinit()でRegisterDialContext("tcp", propagator)する
15-
1614
func RegisterDialContext(netP string, propagator otelprop.TextMapPropagator) {
1715
mysql.RegisterDialContext(netP, DialContext(netP, propagator))
1816
}
1917

2018
func DialContext(netP string, propagator otelprop.TextMapPropagator) mysql.DialContextFunc {
21-
// connector.Connectで呼び出される
19+
// This func is called by connector.Connect
2220
// https://github.com/go-sql-driver/mysql/blob/4591e42e65cf483147a7c7a4f4cfeac81b21c917/connector.go#L37
2321
return func(ctx context.Context, addr string) (net.Conn, error) {
2422
nd := net.Dialer{}

contrib/net/http/picophttp/transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewTransport(base *http.Transport, propagator otelprop.TextMapPropagator) T
2929
t.DialContext = wrapDialContext(base.DialContext, propagator)
3030
t.DialTLSContext = wrapDialContext(base.DialTLSContext, propagator)
3131

32-
// 異なるヘッダのリクエスト同士が同じコネクション使ってはいけない
32+
// Requests with different headers must not use the same connection.
3333
t.DisableKeepAlives = true
3434
return t
3535
}

example/http-client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func main() {
1717
port := flag.String("port", "8080", "request port")
1818
flag.Parse()
19-
// 伝播されたContextを用意
19+
// Prepare propagated context
2020
h := header.NewV1()
2121
h.Set(propagation.EnvIDHeader, "aaaaa")
2222
ctx := propagation.EnvID{}.Extract(context.Background(), propagation.NewPiCoPCarrier(h))

example/http-server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func main() {
3737
}
3838

3939
func handler(w http.ResponseWriter, r *http.Request) {
40-
// 伝播されたContextを確認
40+
// Confirm propagated context
4141
h := header.NewV1()
4242
propagation.EnvID{}.Inject(r.Context(), propagation.NewPiCoPCarrier(h))
4343
w.WriteHeader(http.StatusOK)

example/mysql-client/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"fmt"
77
"log"
88

9-
// _ "github.com/go-sql-driver/mysql" picopmysql内でimportされるので不要
9+
// _ "github.com/go-sql-driver/mysql" // Not required because it is imported by picopmysql
1010
"github.com/picop-rd/picop-go/contrib/github.com/go-sql-driver/mysql/picopmysql"
1111
"github.com/picop-rd/picop-go/propagation"
1212
"github.com/picop-rd/picop-go/protocol/header"
1313
)
1414

1515
func main() {
16-
// 伝播されたContextを用意
16+
// Prepare propagated context
1717
h := header.NewV1()
1818
h.Set(propagation.EnvIDHeader, "aaaaa")
1919
ctx := propagation.EnvID{}.Extract(context.Background(), propagation.NewPiCoPCarrier(h))
@@ -25,7 +25,7 @@ func main() {
2525
log.Fatal(err)
2626
}
2727
defer db.Close()
28-
db.SetMaxIdleConns(0)
28+
db.SetMaxIdleConns(0) // Requests with different headers must not use the same connection.
2929

3030
_, err = db.ExecContext(ctx, "INSERT INTO books(id, name) VALUES (1, \"test1\")")
3131
if err != nil {

example/tcp-client/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func main() {
2727
}
2828
defer conn.Close()
2929

30+
// Prepare propagated context
3031
h := header.NewV1()
3132
h.Set(propagation.EnvIDHeader, "aaaaa")
3233
bconn := picopnet.SenderConn(conn, h)

example/tcp-server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func main() {
3030
}
3131
defer bconn.Close()
3232

33+
// Confirm propagated context
3334
header, err := bconn.ReadHeader()
3435
if err != nil {
3536
log.Fatal(err)

protocol/header/header_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ func TestParse(t *testing.T) {
1717
wantErr bool
1818
}{
1919
{
20-
name: "headerのみを正常に受理できる",
20+
name: "It can accept only a header.",
2121
input: makeV1HeaderByte(11, "key1:value1"),
2222
wantValue: makeV1HeaderStruct("key1", "value1"),
2323
},
2424
{
25-
name: "header+追加データを正常に受理できる",
25+
name: "It can accept a header and additional data.",
2626
input: makeV1HeaderByte(11, "key1:value1testtest"),
2727
wantValue: makeV1HeaderStruct("key1", "value1"),
2828
},
2929
{
30-
name: "複数headerを正常に受理できる",
30+
name: "It can accept headers.",
3131
input: makeV1HeaderByte(39, "key1:value1\r\nkey2:value21\r\nkey2:value22"),
3232
wantValue: makeV1HeaderStruct("key1", "value1", "key2", "value21", "key2", "value22"),
3333
},
3434
{
35-
name: "valueが\"\"でも正常に受理できる",
35+
name: "It can accept an empty value",
3636
input: makeV1HeaderByte(5, "key1:"),
3737
wantValue: makeV1HeaderStruct("key1", ""),
3838
},
3939
{
40-
name: "valueに:があるとエラー",
40+
name: "It can raise an error if the value has :",
4141
input: makeV1HeaderByte(11, "key1:va:ue1"),
4242
wantValue: nil,
4343
wantErr: true,
@@ -69,12 +69,12 @@ func TestHeader_Format(t *testing.T) {
6969
want []byte
7070
}{
7171
{
72-
name: "正しくヘッダをフォーマットできる",
72+
name: "It can format a header.",
7373
value: makeV1HeaderStruct("key1", "value1"),
7474
want: makeV1HeaderByte(11, "Key1:value1"),
7575
},
7676
{
77-
name: "正しく複数ヘッダをフォーマットできる",
77+
name: "It can format headers.",
7878
value: makeV1HeaderStruct("key1", "value1", "key2", "value21", "key2", "value22"),
7979
want: makeV1HeaderByte(39, "Key1:value1\r\nKey2:value21\r\nKey2:value22"),
8080
},

protocol/header/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (h MIMEHeader) String() string {
3333
if len(ret) <= 1 {
3434
return ""
3535
}
36-
return strings.Join(ret[:len(ret)-1], "") // 最後の\r\nを削除
36+
return strings.Join(ret[:len(ret)-1], "") // Delete last \r\n
3737
}
3838

3939
func parseMIMEHeader(data string) (MIMEHeader, error) {

0 commit comments

Comments
 (0)