Skip to content

Commit 177982c

Browse files
committed
proto (wrappers)
1 parent 3002ac4 commit 177982c

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

go.work

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ go 1.20
33
use (
44
./closer
55
./ctxkey
6+
./proto
67
./time
78
)

go.work.sum

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
2+
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
3+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
4+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
25
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
6+
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
7+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
8+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
39
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
10+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
411
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

proto/.golangci.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
output:
2+
formats:
3+
- format: colored-line-number
4+
print-issued-lines: true
5+
print-linter-name: true
6+
7+
linters-settings:
8+
gocognit:
9+
min-complexity: 10
10+
goconst:
11+
min-len: 2
12+
min-occurrences: 2
13+
gosec:
14+
excludes:
15+
# _ instead of err checks
16+
- G104
17+
govet:
18+
enable-all: true
19+
nakedret:
20+
max-func-lines: 10
21+
nolintlint:
22+
require-specific: true
23+
prealloc:
24+
range-loops: true
25+
revive:
26+
rules:
27+
- name: unexported-return
28+
disabled: true
29+
staticcheck:
30+
# SA5001: Allow to ignore returned error before deferring *.Close()
31+
checks: ["all", "-SA5001"]
32+
33+
linters:
34+
disable-all: true
35+
enable:
36+
- bodyclose
37+
- errcheck
38+
- errorlint
39+
- exportloopref
40+
- gocheckcompilerdirectives
41+
- gocognit
42+
- goconst
43+
- goimports
44+
- gosec
45+
- gosimple
46+
- govet
47+
- ineffassign
48+
- makezero
49+
- mnd
50+
- nakedret
51+
- noctx
52+
- nolintlint
53+
- nosprintfhostport
54+
- prealloc
55+
- revive
56+
- staticcheck
57+
- tenv
58+
- testpackage
59+
- typecheck
60+
- unconvert
61+
- unused
62+
- wastedassign
63+
64+
issues:
65+
exclude-rules:
66+
- path: '(.+)_test\.go'
67+
linters:
68+
- gocognit

proto/go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module git.tprs.ru/pl-go/pkg/proto
2+
3+
go 1.20
4+
5+
require google.golang.org/protobuf v1.34.2

proto/go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
2+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
3+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
4+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=

proto/wrappers.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package proto
2+
3+
import (
4+
"time"
5+
6+
"google.golang.org/protobuf/types/known/timestamppb"
7+
)
8+
9+
// Ptr создаёт указатель на значение любого типа.
10+
func Ptr[T any](v T) *T {
11+
return &v
12+
}
13+
14+
// FromTimePtr создаёт экземпляр timestamppb.Timestamp из time.Time. Если передан nil,
15+
// то результатом будет также nil.
16+
func FromTimePtr(t *time.Time) *timestamppb.Timestamp {
17+
if t == nil {
18+
return nil
19+
}
20+
return timestamppb.New(*t)
21+
}

0 commit comments

Comments
 (0)