Skip to content

Commit 393d30a

Browse files
committed
lint
1 parent b70c089 commit 393d30a

File tree

13 files changed

+66
-4
lines changed

13 files changed

+66
-4
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ deps:
33
go mod verify
44
go mod tidy
55

6+
tools:
7+
which go
8+
which golint
9+
which govulncheck
10+
611
# go install golang.org/x/lint/golint@latest
712
lint:
813
gofmt -w=true -s=true -l=true ./

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,46 @@
11
pkg
22
=====================================
3-
43
[![Go](https://github.com/vodolaz095/pkg/actions/workflows/go.yml/badge.svg)](https://github.com/vodolaz095/pkg/actions/workflows/go.yml)
54
[![PkgGoDev](https://pkg.go.dev/badge/github.com/vodolaz095/pkg)](https://pkg.go.dev/github.com/vodolaz095/pkg?tab=doc)
65
[![Go Report Card](https://goreportcard.com/badge/github.com/vodolaz095/pkg)](https://goreportcard.com/report/github.com/vodolaz095/pkg)
76

8-
97
Various functions copy-pasted between different projects.
8+
9+
cryptorand
10+
=======================================
11+
Generate cryptographically secure random strings with alphabet provided
12+
13+
date
14+
=======================================
15+
Date and time helpers - see [moments_test.go](date%2Fmoments_test.go)
16+
17+
math
18+
=======================================
19+
Various generic mathematical functions copy-pasted between different projects.
20+
21+
stopper
22+
=======================================
23+
Make global application context which can be terminated by signals
24+
25+
tracing
26+
=======================================
27+
Opinionated way to configure OpenTelemetry with `jaegertracing/all-in-one` started like with docker compose like this
28+
29+
```yaml
30+
31+
version: "3.11"
32+
33+
services:
34+
jaeger:
35+
container_name: jaeger
36+
image: docker.io/jaegertracing/all-in-one:1.37
37+
ports:
38+
- "16686:16686/tcp" # webui is listening
39+
- "14268:14268/tcp" # accepting spans in compact jaeger thrift format over http
40+
- "6831:6831/udp" # accepting spans in compact jaeger thrift format over udp
41+
42+
```
43+
44+
zerologger
45+
=======================================
46+
Opinionated way to configure zerolog with sane defaults

cryptorand/rand.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ package cryptorand
22

33
import "crypto/rand"
44

5+
// FullAlphabet defines one of possible alphabets used for generating random string
56
const FullAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
7+
8+
// CaptchaAlphabet defines one of possible alphabets used for generating random string
69
const CaptchaAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
10+
11+
// NumbersAlphabet defines one of possible alphabets used for generating random string
712
const NumbersAlphabet = "0123456789"
13+
14+
// CapitalLettersAlphabet defines one of possible alphabets used for generating random string
815
const CapitalLettersAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
916

17+
// GenerateRandomBytes generates cryptographically secure random bytes
1018
func GenerateRandomBytes(n int) ([]byte, error) {
1119
b := make([]byte, n)
1220
_, err := rand.Read(b)
@@ -16,6 +24,7 @@ func GenerateRandomBytes(n int) ([]byte, error) {
1624
return b, nil
1725
}
1826

27+
// GenerateRandomString generates cryptographically secure random string using alphabet provided
1928
func GenerateRandomString(alphabet string, n int) (string, error) {
2029
bytes, err := GenerateRandomBytes(n)
2130
if err != nil {

date/moments_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ func TestMoments(t *testing.T) {
1313
t.Logf("EndOfWeek: %s", EndOfWeek(now).Format(time.Stamp))
1414
t.Logf("BeginningOfMonth: %s", BeginningOfMonth(now).Format(time.Stamp))
1515
t.Logf("EndOfMonth: %s", EndOfMonth(now).Format(time.Stamp))
16-
1716
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
go.opentelemetry.io/otel v1.33.0
1010
go.opentelemetry.io/otel/exporters/jaeger v1.17.0
1111
go.opentelemetry.io/otel/sdk v1.33.0
12+
go.opentelemetry.io/otel/trace v1.33.0
1213
)
1314

1415
require (
@@ -21,7 +22,6 @@ require (
2122
github.com/pmezard/go-difflib v1.0.0 // indirect
2223
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
2324
go.opentelemetry.io/otel/metric v1.33.0 // indirect
24-
go.opentelemetry.io/otel/trace v1.33.0 // indirect
2525
golang.org/x/sys v0.28.0 // indirect
2626
gopkg.in/yaml.v3 v3.0.1 // indirect
2727
)

stopper/cancel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"syscall"
77
)
88

9+
// NewWithContext makes child context which is terminated when process receives stop signals
910
func NewWithContext(parent context.Context) (ctx context.Context, cancel context.CancelFunc) {
1011
return signal.NotifyContext(parent,
1112
syscall.SIGHUP,
@@ -15,6 +16,7 @@ func NewWithContext(parent context.Context) (ctx context.Context, cancel context
1516
syscall.SIGABRT)
1617
}
1718

19+
// New makes context which is terminated when process receives stop signals
1820
func New() (ctx context.Context, cancel context.CancelFunc) {
1921
return NewWithContext(context.Background())
2022
}

tracing/all.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"go.opentelemetry.io/otel/attribute"
77
)
88

9+
// Config is universal config being used to tune tracing
910
type Config struct {
1011
// Protocol sets how we send spans to jaeger - over udp or over http
1112
Protocol string `yaml:"protocol" validate:"required,oneof=udp http UDP HTTP"`
@@ -40,6 +41,7 @@ type Config struct {
4041
Ratio float64 `yaml:"ratio" validate:"required,lte=1,gte=0"`
4142
}
4243

44+
// Start starts telemetry exporter
4345
func Start(cfg Config, extraAttributes ...attribute.KeyValue) (err error) {
4446
switch cfg.Protocol {
4547
case "udp", "UDP":

tracing/compact_jaeger_thrift_http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import (
66
"go.opentelemetry.io/otel/exporters/jaeger"
77
)
88

9+
// HTTPConfig is used to fine tune jaeger exporter to deliver spans via compact thrift protocol to collector http endpoint
910
type HTTPConfig struct {
1011
Endpoint string `yaml:"endpoint"`
1112
Username string `yaml:"username"`
1213
Password string `yaml:"password"`
1314
Ratio float64 `yaml:"ratio" validate:"lte=1,gte=0"`
1415
}
1516

17+
// ConfigureHTTP fine tunes jaeger exporter to deliver spans via compact thrift protocol to collector http endpoint
1618
func ConfigureHTTP(cfg HTTPConfig, extraAttributes ...attribute.KeyValue) (err error) {
1719
if cfg.Ratio == 0 {
1820
log.Debug().Msgf("Tracing disabled")

tracing/compact_jaeger_thrift_udp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"go.opentelemetry.io/otel/exporters/jaeger"
77
)
88

9+
// UDPConfig is used to fine tune jaeger exporter to deliver spans via compact thrift protocol to agent udp listener
910
type UDPConfig struct {
1011
// Host - sets hostname of Jaeger agent, overrides environment value of OTEL_EXPORTER_JAEGER_AGENT_HOST.
1112
// Default value is `localhost`
@@ -17,6 +18,7 @@ type UDPConfig struct {
1718
Ratio float64 `yaml:"ratio" validate:"required,lte=1,gte=0"`
1819
}
1920

21+
// ConfigureUDP fine tunes jaeger exporter to deliver spans via compact thrift protocol to agent udp listener
2022
func ConfigureUDP(cfg UDPConfig, extraAttributes ...attribute.KeyValue) (err error) {
2123
if cfg.Ratio == 0 {
2224
log.Debug().Msgf("Tracing disabled")

tracing/exporter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const defaultTimeout = 10 * time.Second
1212

1313
var exp *jaeger.Exporter
1414

15+
// Wait allows span exporter to inhibit application shutdown until it sends all traces
1516
func Wait(ctx context.Context) (err error) {
1617
if exp != nil {
1718
<-ctx.Done()

0 commit comments

Comments
 (0)