diff --git a/common/buf/buf.go b/common/buf/buf.go index 949ec645..584815f4 100644 --- a/common/buf/buf.go +++ b/common/buf/buf.go @@ -1,3 +1,4 @@ -package buf +// Package buf provides a light-weight memory allocation mechanism. +package buf // import "v2ray.com/core/common/buf" //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg buf -path Buf diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 01a4f0eb..e7583fcc 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -1,4 +1,3 @@ -// Package buf provides a light-weight memory allocation mechanism. package buf import ( diff --git a/common/crypto/crypto.go b/common/crypto/crypto.go index 8483b954..45797a8a 100644 --- a/common/crypto/crypto.go +++ b/common/crypto/crypto.go @@ -1,4 +1,4 @@ // Package crypto provides common crypto libraries for V2Ray. -package crypto +package crypto // import "v2ray.com/core/common/crypto" //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg crypto -path Crypto diff --git a/common/dice/dice.go b/common/dice/dice.go index 014f4c0d..ac03fe9e 100644 --- a/common/dice/dice.go +++ b/common/dice/dice.go @@ -1,6 +1,6 @@ // Package dice contains common functions to generate random number. // It also initialize math/rand with the time in seconds at launch time. -package dice +package dice // import "v2ray.com/core/common/dice" import ( "math/rand" diff --git a/common/errors/errors.go b/common/errors/errors.go index a3c2758d..3e5e0942 100644 --- a/common/errors/errors.go +++ b/common/errors/errors.go @@ -1,5 +1,5 @@ // Package errors is a drop-in replacement for Golang lib 'errors'. -package errors +package errors // import "v2ray.com/core/common/errors" import ( "context" diff --git a/common/log/log.go b/common/log/log.go index e739a1f0..423901b7 100644 --- a/common/log/log.go +++ b/common/log/log.go @@ -1,4 +1,4 @@ -package log +package log // import "v2ray.com/core/common/log" import ( "sync" diff --git a/common/net/net.go b/common/net/net.go index 9cddfe53..b44beedb 100644 --- a/common/net/net.go +++ b/common/net/net.go @@ -1,4 +1,4 @@ // Package net is a drop-in replacement to Golang's net package, with some more functionalities. -package net +package net // import "v2ray.com/core/common/net" //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg net -path Net diff --git a/common/platform/platform.go b/common/platform/platform.go index 96fa7103..3b86ec9d 100644 --- a/common/platform/platform.go +++ b/common/platform/platform.go @@ -1,4 +1,4 @@ -package platform +package platform // import "v2ray.com/core/common/platform" import ( "os" diff --git a/common/predicate/predicate.go b/common/predicate/predicate.go index 326ceba1..fbeb703e 100644 --- a/common/predicate/predicate.go +++ b/common/predicate/predicate.go @@ -1,4 +1,4 @@ -package predicate +package predicate // import "v2ray.com/core/common/predicate" type Predicate func() bool diff --git a/common/protocol/protocol.go b/common/protocol/protocol.go index 6c89418d..edf4e5ca 100644 --- a/common/protocol/protocol.go +++ b/common/protocol/protocol.go @@ -1,3 +1,3 @@ -package protocol +package protocol // import "v2ray.com/core/common/protocol" //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg protocol -path Protocol diff --git a/common/retry/retry.go b/common/retry/retry.go index c2f94ce3..b2c78599 100644 --- a/common/retry/retry.go +++ b/common/retry/retry.go @@ -1,4 +1,4 @@ -package retry +package retry // import "v2ray.com/core/common/retry" //go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg retry -path Retry diff --git a/common/session/session.go b/common/session/session.go index af7aa655..e1be9576 100644 --- a/common/session/session.go +++ b/common/session/session.go @@ -1,12 +1,16 @@ -package session +// Package session provides functions for sessions of incoming requests. +package session // import "v2ray.com/core/common/session" import ( "context" "math/rand" ) +// ID of a session. type ID uint32 +// NewID generates a new ID. The generated ID is high likely to be unique, but not cryptographically secure. +// The generated ID will never be 0. func NewID() ID { for { id := ID(rand.Uint32()) @@ -22,10 +26,12 @@ const ( idSessionKey sessionKey = iota ) +// ContextWithID returns a new context with the given ID. func ContextWithID(ctx context.Context, id ID) context.Context { return context.WithValue(ctx, idSessionKey, id) } +// IDFromContext returns ID in this context, or 0 if not contained. func IDFromContext(ctx context.Context) ID { if id, ok := ctx.Value(idSessionKey).(ID); ok { return id diff --git a/common/uuid/uuid.go b/common/uuid/uuid.go index 06b219a0..fa90f915 100755 --- a/common/uuid/uuid.go +++ b/common/uuid/uuid.go @@ -1,4 +1,4 @@ -package uuid +package uuid // import "v2ray.com/core/common/uuid" import ( "bytes"