Skip to content

Commit fc1dfb7

Browse files
committed
comment update;standardize const naming for package gtcp/gudp
1 parent dc407bf commit fc1dfb7

17 files changed

+114
-112
lines changed

internal/command/command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
argumentRegex = regexp.MustCompile(`^\-{1,2}([\w\?\.\-]+)(=){0,1}(.*)$`)
2121
)
2222

23-
// Custom initialization.
23+
// Init does custom initialization.
2424
func Init(args ...string) {
2525
if len(args) == 0 {
2626
if len(defaultParsedArgs) == 0 && len(defaultParsedOptions) == 0 {

internal/empty/empty.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,9 @@ func IsEmpty(value interface{}) bool {
286286
//}
287287

288288
// IsNil checks whether given `value` is nil.
289-
// Parameter `traceSource` is used for tracing to the source variable if given `value` is type
290-
// of a pinter that also points to a pointer. It returns nil if the source is nil when `traceSource`
291-
// is true.
292-
// Note that it might use reflect feature which affects performance a little bit.
289+
// Parameter `traceSource` is used for tracing to the source variable if given `value` is type of pinter
290+
// that also points to a pointer. It returns nil if the source is nil when `traceSource` is true.
291+
// Note that it might use reflect feature which affects performance a little.
293292
func IsNil(value interface{}, traceSource ...bool) bool {
294293
if value == nil {
295294
return true

internal/structs/structs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// If a copy of the MIT was not distributed with this file,
55
// You can obtain one at https://github.com/gogf/gf.
66

7-
// Package structs provides functions for struct conversion.
7+
// Package structs provides functions for struct information retrieving and struct conversion.
88
//
99
// Inspired and improved from: https://github.com/fatih/structs
1010
package structs

internal/structs/structs_field.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (f *Field) Tag(key string) string {
1616

1717
// TagLookup returns the value associated with key in the tag string.
1818
// If the key is present in the tag the value (which may be empty)
19-
// is returned. Otherwise the returned value will be the empty string.
19+
// is returned. Otherwise, the returned value will be the empty string.
2020
// The ok return value reports whether the value was explicitly set in
2121
// the tag string. If the tag does not have the conventional format,
2222
// the value returned by Lookup is unspecified.

internal/structs/structs_tag.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func ParseTag(tag string) map[string]string {
5353
if i >= len(tag) {
5454
break
5555
}
56-
quotedValue := string(tag[:i+1])
56+
quotedValue := tag[:i+1]
5757
tag = tag[i+1:]
5858
value, err := strconv.Unquote(quotedValue)
5959
if err != nil {
@@ -137,6 +137,7 @@ func getFieldValues(value interface{}) ([]*Field, error) {
137137
goto exitLoop
138138
}
139139
}
140+
140141
exitLoop:
141142
for reflectKind == reflect.Ptr {
142143
reflectValue = reflectValue.Elem()

internal/structs/structs_type.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ func StructType(object interface{}) (*Type, error) {
3737
reflectValue = reflectValue.Elem()
3838
reflectKind = reflectValue.Kind()
3939
}
40+
4041
case reflect.Array, reflect.Slice:
4142
reflectValue = reflect.New(reflectValue.Type().Elem()).Elem()
4243
reflectKind = reflectValue.Kind()
44+
4345
default:
4446
goto exitLoop
4547
}
4648
}
49+
4750
exitLoop:
4851
for reflectKind == reflect.Ptr {
4952
reflectValue = reflectValue.Elem()
@@ -63,7 +66,7 @@ exitLoop:
6366
}, nil
6467
}
6568

66-
// Signature returns an unique string as this type.
69+
// Signature returns a unique string as this type.
6770
func (t Type) Signature() string {
6871
return t.PkgPath() + "/" + t.String()
6972
}

internal/utils/utils_io.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ type ReadCloser struct {
2121
repeatable bool
2222
}
2323

24-
// NewRepeatReadCloser creates and returns a RepeatReadCloser object.
24+
// NewReadCloser creates and returns a RepeatReadCloser object.
2525
func NewReadCloser(content []byte, repeatable bool) io.ReadCloser {
2626
return &ReadCloser{
2727
content: content,
2828
repeatable: repeatable,
2929
}
3030
}
3131

32-
// NewRepeatReadCloserWithReadCloser creates and returns a RepeatReadCloser object
32+
// NewReadCloserWithReadCloser creates and returns a RepeatReadCloser object
3333
// with given io.ReadCloser.
3434
func NewReadCloserWithReadCloser(r io.ReadCloser, repeatable bool) (io.ReadCloser, error) {
3535
content, err := ioutil.ReadAll(r)

net/gtcp/gtcp_conn.go

+27-27
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ import (
1515
"time"
1616
)
1717

18-
// TCP connection object.
18+
// Conn is the TCP connection object.
1919
type Conn struct {
20-
net.Conn // Underlying TCP connection object.
21-
reader *bufio.Reader // Buffer reader for connection.
22-
recvDeadline time.Time // Timeout point for reading.
23-
sendDeadline time.Time // Timeout point for writing.
24-
recvBufferWait time.Duration // Interval duration for reading buffer.
20+
net.Conn // Underlying TCP connection object.
21+
reader *bufio.Reader // Buffer reader for connection.
22+
receiveDeadline time.Time // Timeout point for reading.
23+
sendDeadline time.Time // Timeout point for writing.
24+
receiveBufferWait time.Duration // Interval duration for reading buffer.
2525
}
2626

2727
const (
2828
// Default interval for reading buffer.
29-
gRECV_ALL_WAIT_TIMEOUT = time.Millisecond
29+
receiveAllWaitTimeout = time.Millisecond
3030
)
3131

3232
// NewConn creates and returns a new connection with given address.
@@ -61,11 +61,11 @@ func NewConnKeyCrt(addr, crtFile, keyFile string) (*Conn, error) {
6161
// NewConnByNetConn creates and returns a TCP connection object with given net.Conn object.
6262
func NewConnByNetConn(conn net.Conn) *Conn {
6363
return &Conn{
64-
Conn: conn,
65-
reader: bufio.NewReader(conn),
66-
recvDeadline: time.Time{},
67-
sendDeadline: time.Time{},
68-
recvBufferWait: gRECV_ALL_WAIT_TIMEOUT,
64+
Conn: conn,
65+
reader: bufio.NewReader(conn),
66+
receiveDeadline: time.Time{},
67+
sendDeadline: time.Time{},
68+
receiveBufferWait: receiveAllWaitTimeout,
6969
}
7070
}
7171

@@ -84,7 +84,7 @@ func (c *Conn) Send(data []byte, retry ...Retry) error {
8484
if len(retry) > 0 {
8585
retry[0].Count--
8686
if retry[0].Interval == 0 {
87-
retry[0].Interval = gDEFAULT_RETRY_INTERVAL
87+
retry[0].Interval = defaultRetryInternal
8888
}
8989
time.Sleep(retry[0].Interval)
9090
}
@@ -113,13 +113,13 @@ func (c *Conn) Recv(length int, retry ...Retry) ([]byte, error) {
113113
if length > 0 {
114114
buffer = make([]byte, length)
115115
} else {
116-
buffer = make([]byte, gDEFAULT_READ_BUFFER_SIZE)
116+
buffer = make([]byte, defaultReadBufferSize)
117117
}
118118

119119
for {
120120
if length < 0 && index > 0 {
121121
bufferWait = true
122-
if err = c.SetReadDeadline(time.Now().Add(c.recvBufferWait)); err != nil {
122+
if err = c.SetReadDeadline(time.Now().Add(c.receiveBufferWait)); err != nil {
123123
return nil, err
124124
}
125125
}
@@ -132,9 +132,9 @@ func (c *Conn) Recv(length int, retry ...Retry) ([]byte, error) {
132132
break
133133
}
134134
} else {
135-
if index >= gDEFAULT_READ_BUFFER_SIZE {
135+
if index >= defaultReadBufferSize {
136136
// If it exceeds the buffer size, it then automatically increases its buffer size.
137-
buffer = append(buffer, make([]byte, gDEFAULT_READ_BUFFER_SIZE)...)
137+
buffer = append(buffer, make([]byte, defaultReadBufferSize)...)
138138
} else {
139139
// It returns immediately if received size is lesser than buffer size.
140140
if !bufferWait {
@@ -150,7 +150,7 @@ func (c *Conn) Recv(length int, retry ...Retry) ([]byte, error) {
150150
}
151151
// Re-set the timeout when reading data.
152152
if bufferWait && isTimeout(err) {
153-
if err = c.SetReadDeadline(c.recvDeadline); err != nil {
153+
if err = c.SetReadDeadline(c.receiveDeadline); err != nil {
154154
return nil, err
155155
}
156156
err = nil
@@ -163,7 +163,7 @@ func (c *Conn) Recv(length int, retry ...Retry) ([]byte, error) {
163163
}
164164
retry[0].Count--
165165
if retry[0].Interval == 0 {
166-
retry[0].Interval = gDEFAULT_RETRY_INTERVAL
166+
retry[0].Interval = defaultRetryInternal
167167
}
168168
time.Sleep(retry[0].Interval)
169169
continue
@@ -230,10 +230,10 @@ func (c *Conn) RecvTil(til []byte, retry ...Retry) ([]byte, error) {
230230

231231
// RecvWithTimeout reads data from the connection with timeout.
232232
func (c *Conn) RecvWithTimeout(length int, timeout time.Duration, retry ...Retry) (data []byte, err error) {
233-
if err := c.SetRecvDeadline(time.Now().Add(timeout)); err != nil {
233+
if err := c.SetreceiveDeadline(time.Now().Add(timeout)); err != nil {
234234
return nil, err
235235
}
236-
defer c.SetRecvDeadline(time.Time{})
236+
defer c.SetreceiveDeadline(time.Time{})
237237
data, err = c.Recv(length, retry...)
238238
return
239239
}
@@ -269,16 +269,16 @@ func (c *Conn) SendRecvWithTimeout(data []byte, length int, timeout time.Duratio
269269
func (c *Conn) SetDeadline(t time.Time) error {
270270
err := c.Conn.SetDeadline(t)
271271
if err == nil {
272-
c.recvDeadline = t
272+
c.receiveDeadline = t
273273
c.sendDeadline = t
274274
}
275275
return err
276276
}
277277

278-
func (c *Conn) SetRecvDeadline(t time.Time) error {
278+
func (c *Conn) SetreceiveDeadline(t time.Time) error {
279279
err := c.SetReadDeadline(t)
280280
if err == nil {
281-
c.recvDeadline = t
281+
c.receiveDeadline = t
282282
}
283283
return err
284284
}
@@ -291,8 +291,8 @@ func (c *Conn) SetSendDeadline(t time.Time) error {
291291
return err
292292
}
293293

294-
// SetRecvBufferWait sets the buffer waiting timeout when reading all data from connection.
294+
// SetreceiveBufferWait sets the buffer waiting timeout when reading all data from connection.
295295
// The waiting duration cannot be too long which might delay receiving data from remote address.
296-
func (c *Conn) SetRecvBufferWait(bufferWaitDuration time.Duration) {
297-
c.recvBufferWait = bufferWaitDuration
296+
func (c *Conn) SetreceiveBufferWait(bufferWaitDuration time.Duration) {
297+
c.receiveBufferWait = bufferWaitDuration
298298
}

net/gtcp/gtcp_conn_pkg.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
)
1414

1515
const (
16-
gPKG_HEADER_SIZE_DEFAULT = 2 // Header size for simple package protocol.
17-
gPKG_HEADER_SIZE_MAX = 4 // Max header size for simple package protocol.
16+
pkgHeaderSizeDefault = 2 // Header size for simple package protocol.
17+
pkgHeaderSizeMax = 4 // Max header size for simple package protocol.
1818
)
1919

20-
// Package option for simple protocol.
20+
// PkgOption is package option for simple protocol.
2121
type PkgOption struct {
2222
// HeaderSize is used to mark the data length for next data receiving.
2323
// It's 2 bytes in default, 4 bytes max, which stands for the max data length
@@ -51,10 +51,10 @@ func (c *Conn) SendPkg(data []byte, option ...PkgOption) error {
5151
length, pkgOption.MaxDataSize,
5252
)
5353
}
54-
offset := gPKG_HEADER_SIZE_MAX - pkgOption.HeaderSize
55-
buffer := make([]byte, gPKG_HEADER_SIZE_MAX+len(data))
54+
offset := pkgHeaderSizeMax - pkgOption.HeaderSize
55+
buffer := make([]byte, pkgHeaderSizeMax+len(data))
5656
binary.BigEndian.PutUint32(buffer[0:], uint32(length))
57-
copy(buffer[gPKG_HEADER_SIZE_MAX:], data)
57+
copy(buffer[pkgHeaderSizeMax:], data)
5858
if pkgOption.Retry.Count > 0 {
5959
return c.Send(buffer[offset:], pkgOption.Retry)
6060
}
@@ -128,10 +128,10 @@ func (c *Conn) RecvPkg(option ...PkgOption) (result []byte, err error) {
128128

129129
// RecvPkgWithTimeout reads data from connection with timeout using simple package protocol.
130130
func (c *Conn) RecvPkgWithTimeout(timeout time.Duration, option ...PkgOption) (data []byte, err error) {
131-
if err := c.SetRecvDeadline(time.Now().Add(timeout)); err != nil {
131+
if err := c.SetreceiveDeadline(time.Now().Add(timeout)); err != nil {
132132
return nil, err
133133
}
134-
defer c.SetRecvDeadline(time.Time{})
134+
defer c.SetreceiveDeadline(time.Time{})
135135
data, err = c.RecvPkg(option...)
136136
return
137137
}
@@ -144,12 +144,12 @@ func getPkgOption(option ...PkgOption) (*PkgOption, error) {
144144
pkgOption = option[0]
145145
}
146146
if pkgOption.HeaderSize == 0 {
147-
pkgOption.HeaderSize = gPKG_HEADER_SIZE_DEFAULT
147+
pkgOption.HeaderSize = pkgHeaderSizeDefault
148148
}
149-
if pkgOption.HeaderSize > gPKG_HEADER_SIZE_MAX {
149+
if pkgOption.HeaderSize > pkgHeaderSizeMax {
150150
return nil, fmt.Errorf(
151151
`package header size %d definition exceeds max header size %d`,
152-
pkgOption.HeaderSize, gPKG_HEADER_SIZE_MAX,
152+
pkgOption.HeaderSize, pkgHeaderSizeMax,
153153
)
154154
}
155155
if pkgOption.MaxDataSize == 0 {

net/gtcp/gtcp_func.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
)
1717

1818
const (
19-
gDEFAULT_CONN_TIMEOUT = 30 * time.Second // Default connection timeout.
20-
gDEFAULT_RETRY_INTERVAL = 100 * time.Millisecond // Default retry interval.
21-
gDEFAULT_READ_BUFFER_SIZE = 128 // (Byte) Buffer size for reading.
19+
defaultConnTimeout = 30 * time.Second // Default connection timeout.
20+
defaultRetryInternal = 100 * time.Millisecond // Default retry interval.
21+
defaultReadBufferSize = 128 // (Byte) Buffer size for reading.
2222
)
2323

2424
type Retry struct {
@@ -29,7 +29,7 @@ type Retry struct {
2929
// NewNetConn creates and returns a net.Conn with given address like "127.0.0.1:80".
3030
// The optional parameter <timeout> specifies the timeout for dialing connection.
3131
func NewNetConn(addr string, timeout ...time.Duration) (net.Conn, error) {
32-
d := gDEFAULT_CONN_TIMEOUT
32+
d := defaultConnTimeout
3333
if len(timeout) > 0 {
3434
d = timeout[0]
3535
}
@@ -40,7 +40,7 @@ func NewNetConn(addr string, timeout ...time.Duration) (net.Conn, error) {
4040
// The optional parameter <timeout> specifies the timeout for dialing connection.
4141
func NewNetConnTLS(addr string, tlsConfig *tls.Config, timeout ...time.Duration) (net.Conn, error) {
4242
dialer := &net.Dialer{
43-
Timeout: gDEFAULT_CONN_TIMEOUT,
43+
Timeout: defaultConnTimeout,
4444
}
4545
if len(timeout) > 0 {
4646
dialer.Timeout = timeout[0]

0 commit comments

Comments
 (0)