Skip to content

Commit

Permalink
proto (wrappers)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-menshchikov committed Nov 10, 2024
1 parent 3002ac4 commit 177982c
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ go 1.20
use (
./closer
./ctxkey
./proto
./time
)
7 changes: 7 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
68 changes: 68 additions & 0 deletions proto/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
output:
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
gocognit:
min-complexity: 10
goconst:
min-len: 2
min-occurrences: 2
gosec:
excludes:
# _ instead of err checks
- G104
govet:
enable-all: true
nakedret:
max-func-lines: 10
nolintlint:
require-specific: true
prealloc:
range-loops: true
revive:
rules:
- name: unexported-return
disabled: true
staticcheck:
# SA5001: Allow to ignore returned error before deferring *.Close()
checks: ["all", "-SA5001"]

linters:
disable-all: true
enable:
- bodyclose
- errcheck
- errorlint
- exportloopref
- gocheckcompilerdirectives
- gocognit
- goconst
- goimports
- gosec
- gosimple
- govet
- ineffassign
- makezero
- mnd
- nakedret
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- revive
- staticcheck
- tenv
- testpackage
- typecheck
- unconvert
- unused
- wastedassign

issues:
exclude-rules:
- path: '(.+)_test\.go'
linters:
- gocognit
5 changes: 5 additions & 0 deletions proto/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module git.tprs.ru/pl-go/pkg/proto

go 1.20

require google.golang.org/protobuf v1.34.2
4 changes: 4 additions & 0 deletions proto/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
21 changes: 21 additions & 0 deletions proto/wrappers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package proto

import (
"time"

"google.golang.org/protobuf/types/known/timestamppb"
)

// Ptr создаёт указатель на значение любого типа.
func Ptr[T any](v T) *T {
return &v
}

// FromTimePtr создаёт экземпляр timestamppb.Timestamp из time.Time. Если передан nil,
// то результатом будет также nil.
func FromTimePtr(t *time.Time) *timestamppb.Timestamp {
if t == nil {
return nil
}
return timestamppb.New(*t)
}

0 comments on commit 177982c

Please sign in to comment.