Fix all golint comment related problems in the pkg packages

This commit is contained in:
Ola Bini 2019-12-21 17:19:26 +00:00
parent 65d43576a0
commit e7589e706e
No known key found for this signature in database
GPG key ID: 6786A150F6A2B28F
17 changed files with 47 additions and 18 deletions

View file

@ -4,8 +4,8 @@
package acl package acl
// Per-channel permissions
const ( const (
// Per-channel permissions
NonePermission = 0x0 NonePermission = 0x0
WritePermission = 0x1 WritePermission = 0x1
TraversePermission = 0x2 TraversePermission = 0x2

View file

@ -1,6 +1,7 @@
// Copyright (c) 2010-2013 The Grumble Authors // Copyright (c) 2010-2013 The Grumble Authors
// The use of this source code is goverened by a BSD-style // The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file. // license that can be found in the LICENSE-file.
package acl package acl
import ( import (

View file

@ -10,9 +10,11 @@ import (
) )
const ( const (
// ISODate represents ISO 8601 formatting
ISODate = "2006-01-02T15:04:05" ISODate = "2006-01-02T15:04:05"
) )
// Ban contains information about a specific ban
type Ban struct { type Ban struct {
IP net.IP IP net.IP
Mask int Mask int
@ -23,7 +25,7 @@ type Ban struct {
Duration uint32 Duration uint32
} }
// Create a net.IPMask from a specified amount of mask bits // IPMask creates a net.IPMask from a specified amount of mask bits
func (ban Ban) IPMask() (mask net.IPMask) { func (ban Ban) IPMask() (mask net.IPMask) {
allbits := ban.Mask allbits := ban.Mask
for i := 0; i < 16; i++ { for i := 0; i < 16; i++ {
@ -48,7 +50,7 @@ func (ban Ban) Match(ip net.IP) bool {
return banned.Equal(masked) return banned.Equal(masked)
} }
// Set Start date from an ISO 8601 date (in UTC) // SetISOStartDate sets Start date from an ISO 8601 date (in UTC)
func (ban *Ban) SetISOStartDate(isodate string) { func (ban *Ban) SetISOStartDate(isodate string) {
startTime, err := time.Parse(ISODate, isodate) startTime, err := time.Parse(ISODate, isodate)
if err != nil { if err != nil {

View file

@ -2,7 +2,7 @@
// The use of this source code is goverened by a BSD-style // The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file. // license that can be found in the LICENSE-file.
// This package implements a simple disk-persisted content-addressed blobstore. // Package blobstore implements a simple disk-persisted content-addressed blobstore.
package blobstore package blobstore
import ( import (

View file

@ -13,6 +13,7 @@ import (
const decryptHistorySize = 0x100 const decryptHistorySize = 0x100
// CryptoMode represents a specific cryptographic mode
type CryptoMode interface { type CryptoMode interface {
NonceSize() int NonceSize() int
KeySize() int KeySize() int
@ -23,6 +24,7 @@ type CryptoMode interface {
Decrypt(dst []byte, src []byte, nonce []byte) bool Decrypt(dst []byte, src []byte, nonce []byte) bool
} }
// CryptState represents the current state of a cryptographic operation
type CryptState struct { type CryptState struct {
Key []byte Key []byte
EncryptIV []byte EncryptIV []byte
@ -62,6 +64,7 @@ func createMode(mode string) (CryptoMode, error) {
return nil, errors.New("cryptstate: no such CryptoMode") return nil, errors.New("cryptstate: no such CryptoMode")
} }
// GenerateKey will generate a key for the specific mode
func (cs *CryptState) GenerateKey(mode string) error { func (cs *CryptState) GenerateKey(mode string) error {
cm, err := createMode(mode) cm, err := createMode(mode)
if err != nil { if err != nil {
@ -93,6 +96,7 @@ func (cs *CryptState) GenerateKey(mode string) error {
return nil return nil
} }
// SetKey will set the cryptographic key for a specific mode
func (cs *CryptState) SetKey(mode string, key []byte, eiv []byte, div []byte) error { func (cs *CryptState) SetKey(mode string, key []byte, eiv []byte, div []byte) error {
cm, err := createMode(mode) cm, err := createMode(mode)
if err != nil { if err != nil {
@ -115,6 +119,7 @@ func (cs *CryptState) Overhead() int {
return 1 + cs.mode.Overhead() return 1 + cs.mode.Overhead()
} }
// Decrypt decrypts the source into the destination
func (cs *CryptState) Decrypt(dst, src []byte) error { func (cs *CryptState) Decrypt(dst, src []byte) error {
if len(src) < cs.Overhead() { if len(src) < cs.Overhead() {
return errors.New("cryptstate: crypted length too short to decrypt") return errors.New("cryptstate: crypted length too short to decrypt")
@ -228,6 +233,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) error {
return nil return nil
} }
// Encrypt will encrypt the source into the destination
func (cs *CryptState) Encrypt(dst, src []byte) { func (cs *CryptState) Encrypt(dst, src []byte) {
// First, increase our IV // First, increase our IV
for i := range cs.EncryptIV { for i := range cs.EncryptIV {

View file

@ -6,6 +6,7 @@ package freezer
type typeKind uint32 type typeKind uint32
// The different types of data that can be frozen
const ( const (
ServerType typeKind = iota ServerType typeKind = iota
ConfigKeyValuePairType ConfigKeyValuePairType

View file

@ -23,14 +23,14 @@ func isEOF(err error) bool {
return false return false
} }
// Type Walker implements a method for // Walker implements a method for
// iterating the transaction groups of an // iterating the transaction groups of an
// immutable Log. // immutable Log.
type Walker struct { type Walker struct {
r io.Reader r io.Reader
} }
// Type txReader imlpements a checksumming reader, intended // txReader imlpements a checksumming reader, intended
// for reading transaction groups of a Log. // for reading transaction groups of a Log.
// //
// Besides auto-checksumming the read content, it also // Besides auto-checksumming the read content, it also
@ -79,7 +79,7 @@ func (txr *txReader) Consumed() int {
return txr.consumed return txr.consumed
} }
// Create a new Walker that iterates over the log entries of a given Reader. // NewReaderWalker creates a new Walker that iterates over the log entries of a given Reader.
func NewReaderWalker(r io.Reader) (walker *Walker, err error) { func NewReaderWalker(r io.Reader) (walker *Walker, err error) {
walker = new(Walker) walker = new(Walker)
walker.r = r walker.r = r

View file

@ -41,7 +41,7 @@ type Log struct {
wc io.WriteCloser wc io.WriteCloser
} }
// Type LogTx represents a transaction in the log. // LogTx represents a transaction in the log.
// Transactions can be used to group several changes into an // Transactions can be used to group several changes into an
// atomic entity in the log file. // atomic entity in the log file.
type LogTx struct { type LogTx struct {
@ -51,7 +51,7 @@ type LogTx struct {
numops int numops int
} }
// Create a new log file // NewLogFile creates a new log file
func NewLogFile(fn string) (*Log, error) { func NewLogFile(fn string) (*Log, error) {
f, err := os.Create(fn) f, err := os.Create(fn)
if err != nil { if err != nil {
@ -69,7 +69,7 @@ func (log *Log) Close() error {
return log.wc.Close() return log.wc.Close()
} }
// Append a log entry // Put will append a log entry
// //
// This method implicitly creates a transaction // This method implicitly creates a transaction
// group for this single Put operation. It is merely // group for this single Put operation. It is merely
@ -83,7 +83,7 @@ func (log *Log) Put(value interface{}) (err error) {
return tx.Commit() return tx.Commit()
} }
// Begin a transaction // BeginTx begins a transaction
func (log *Log) BeginTx() *LogTx { func (log *Log) BeginTx() *LogTx {
tx := &LogTx{} tx := &LogTx{}
tx.log = log tx.log = log
@ -92,7 +92,7 @@ func (log *Log) BeginTx() *LogTx {
return tx return tx
} }
// Append a log entry to the transaction. // Put will append a log entry to the transaction.
// The transaction's log entries will not be persisted to // The transaction's log entries will not be persisted to
// the log until the Commit has been called on the transaction. // the log until the Commit has been called on the transaction.
func (tx *LogTx) Put(value interface{}) (err error) { func (tx *LogTx) Put(value interface{}) (err error) {

View file

@ -12,6 +12,7 @@ import (
"strings" "strings"
) )
// Options contains the different possible HTML filtering options
type Options struct { type Options struct {
StripHTML bool StripHTML bool
MaxTextMessageLength int MaxTextMessageLength int
@ -24,6 +25,7 @@ var defaultOptions Options = Options{
MaxImageMessageLength: 1024 * 1024, MaxImageMessageLength: 1024 * 1024,
} }
// Errors that can happen in this module
var ( var (
ErrExceedsTextMessageLength = errors.New("Exceeds text message length") ErrExceedsTextMessageLength = errors.New("Exceeds text message length")
ErrExceedsImageMessageLength = errors.New("Exceeds image message length") ErrExceedsImageMessageLength = errors.New("Exceeds image message length")

View file

@ -22,6 +22,7 @@ type LogTarget struct {
memLog *bytes.Buffer memLog *bytes.Buffer
} }
// Target is the current log target
var Target LogTarget var Target LogTarget
// Write writes a log message to all registered io.Writers // Write writes a log message to all registered io.Writers

View file

@ -4,6 +4,7 @@
package mumbleproto package mumbleproto
// All different message types
const ( const (
MessageVersion uint16 = iota MessageVersion uint16 = iota
MessageUDPTunnel MessageUDPTunnel
@ -32,6 +33,7 @@ const (
MessageServerConfig MessageServerConfig
) )
// All different UDP message types
const ( const (
UDPMessageVoiceCELTAlpha = iota UDPMessageVoiceCELTAlpha = iota
UDPMessagePing UDPMessagePing

View file

@ -9,6 +9,7 @@ import (
"math" "math"
) )
// PacketData contains one packet of information
type PacketData struct { type PacketData struct {
Buf []byte Buf []byte
offset int offset int
@ -17,6 +18,7 @@ type PacketData struct {
ok bool ok bool
} }
// New creates a new packet data from the buffer
func New(buf []byte) (pds *PacketData) { func New(buf []byte) (pds *PacketData) {
pds = new(PacketData) pds = new(PacketData)
pds.Buf = buf pds.Buf = buf
@ -25,10 +27,12 @@ func New(buf []byte) (pds *PacketData) {
return return
} }
// IsValid checks whether the current packet data is valid
func (pds *PacketData) IsValid() bool { func (pds *PacketData) IsValid() bool {
return pds.ok return pds.ok
} }
// Skip will skip some data
func (pds *PacketData) Skip(skip int) { func (pds *PacketData) Skip(skip int) {
if pds.Left() >= skip { if pds.Left() >= skip {
pds.offset += skip pds.offset += skip
@ -299,7 +303,7 @@ func (pds *PacketData) PutFloat64(val float64) {
pds.append(bits & 0xff) pds.append(bits & 0xff)
} }
// Copy a buffer out of the PacketData into dst. // CopyBytes will copy a buffer out of the PacketData into dst.
func (pds *PacketData) CopyBytes(dst []byte) { func (pds *PacketData) CopyBytes(dst []byte) {
if pds.Left() >= len(dst) { if pds.Left() >= len(dst) {
if copy(dst, pds.Buf[pds.offset:pds.offset+len(dst)]) != len(dst) { if copy(dst, pds.Buf[pds.offset:pds.offset+len(dst)]) != len(dst) {
@ -310,7 +314,7 @@ func (pds *PacketData) CopyBytes(dst []byte) {
} }
} }
// Put a buffer src into the PacketData at the // PutBytes will put a buffer src into the PacketData at the
// current offset. // current offset.
func (pds *PacketData) PutBytes(src []byte) { func (pds *PacketData) PutBytes(src []byte) {
if pds.Left() >= len(src) { if pds.Left() >= len(src) {

View file

@ -4,8 +4,10 @@
package replacefile package replacefile
// Flag is a flag that allows you to ignore some errors
type Flag uint32 type Flag uint32
// The types of errors that can be ignored
const ( const (
IgnoreMergeErrors Flag = 0x2 IgnoreMergeErrors Flag = 0x2
IgnoreACLErrors Flag = 0x4 IgnoreACLErrors Flag = 0x4

View file

@ -10,6 +10,7 @@ import (
"errors" "errors"
) )
// The different types of errors that can happen if we're not on windows
var ( var (
errOnlyWindows = errors.New("replacefile: only implemented on Windows") errOnlyWindows = errors.New("replacefile: only implemented on Windows")
ErrUnableToMoveReplacement error = errOnlyWindows ErrUnableToMoveReplacement error = errOnlyWindows
@ -17,6 +18,7 @@ var (
ErrUnableToRemoveReplaced error = errOnlyWindows ErrUnableToRemoveReplaced error = errOnlyWindows
) )
// ReplaceFile tries to replace the file
func ReplaceFile(replaced string, replacement string, backup string, flags Flag) error { func ReplaceFile(replaced string, replacement string, backup string, flags Flag) error {
return errOnlyWindows return errOnlyWindows
} }

View file

@ -22,12 +22,13 @@ var defaultCfg = map[string]string{
"SendVersion": "true", "SendVersion": "true",
} }
// Config contains all configurations
type Config struct { type Config struct {
cfgMap map[string]string cfgMap map[string]string
mutex sync.RWMutex mutex sync.RWMutex
} }
// Create a new Config using cfgMap as the intial internal config map. // New creates a new Config using cfgMap as the intial internal config map.
// If cfgMap is nil, ConfigWithMap will create a new config map. // If cfgMap is nil, ConfigWithMap will create a new config map.
func New(cfgMap map[string]string) *Config { func New(cfgMap map[string]string) *Config {
if cfgMap == nil { if cfgMap == nil {

View file

@ -10,7 +10,7 @@ import (
"sync" "sync"
) )
// A SessionPool is a pool for session IDs. // SessionPool is a pool for session IDs.
// IDs are re-used in MRU order, for ease of implementation in Go. // IDs are re-used in MRU order, for ease of implementation in Go.
type SessionPool struct { type SessionPool struct {
mutex sync.Mutex mutex sync.Mutex
@ -19,13 +19,13 @@ type SessionPool struct {
cur uint32 cur uint32
} }
// Create a new SessionPool container. // New creates a new SessionPool container.
func New() (pool *SessionPool) { func New() (pool *SessionPool) {
pool = new(SessionPool) pool = new(SessionPool)
return return
} }
// Enable use-tracking for the SessionPool. // EnableUseTracking will enable use-tracking for the SessionPool.
// //
// When enabled, the SessionPool stores all session IDs // When enabled, the SessionPool stores all session IDs
// returned by Get() internally. When an ID is reclaimed, // returned by Get() internally. When an ID is reclaimed,

View file

@ -23,6 +23,7 @@ var upgrader = websocket.Upgrader{
}, },
} }
// Listener represents a specific network listener
type Listener struct { type Listener struct {
sockets chan *conn sockets chan *conn
done chan struct{} done chan struct{}
@ -31,6 +32,7 @@ type Listener struct {
logger *log.Logger logger *log.Logger
} }
// NewListener creates a new listener
func NewListener(laddr net.Addr, logger *log.Logger) *Listener { func NewListener(laddr net.Addr, logger *log.Logger) *Listener {
return &Listener{ return &Listener{
sockets: make(chan *conn), sockets: make(chan *conn),
@ -40,6 +42,7 @@ func NewListener(laddr net.Addr, logger *log.Logger) *Listener {
} }
} }
// Accept blocks and waits for a new connection
func (l *Listener) Accept() (net.Conn, error) { func (l *Listener) Accept() (net.Conn, error) {
if atomic.LoadInt32(&l.closed) != 0 { if atomic.LoadInt32(&l.closed) != 0 {
return nil, fmt.Errorf("accept ws %v: use of closed websocket listener", l.addr) return nil, fmt.Errorf("accept ws %v: use of closed websocket listener", l.addr)
@ -52,6 +55,7 @@ func (l *Listener) Accept() (net.Conn, error) {
} }
} }
// Close will close the underlying listener
func (l *Listener) Close() error { func (l *Listener) Close() error {
if !atomic.CompareAndSwapInt32(&l.closed, 0, 1) { if !atomic.CompareAndSwapInt32(&l.closed, 0, 1) {
return fmt.Errorf("close ws %v: use of closed websocket listener", l.addr) return fmt.Errorf("close ws %v: use of closed websocket listener", l.addr)
@ -60,6 +64,7 @@ func (l *Listener) Close() error {
return nil return nil
} }
// Addr returns the internal address
func (l *Listener) Addr() net.Addr { func (l *Listener) Addr() net.Addr {
return l.addr return l.addr
} }