add doc comments

This commit is contained in:
Diego Fernando Carrión 2021-08-31 07:25:56 +02:00
parent a9ba0455cd
commit 3295c0a525

View File

@ -1,101 +1,106 @@
// Package sugar
package sugar
import "fmt"
import (
"fmt"
"os"
)
/*
* Literal Addressers
*/
// int
// IntPtr takes an int literal and returns a pointer.
func IntPtr(v int) *int {
return &v
}
// int8
// Int8Ptr takes an int8 literal and returns a pointer.
func Int8Ptr(v int8) *int8 {
return &v
}
// int16
// Int16Ptr takes an int16 literal and returns a pointer.
func Int16Ptr(v int16) *int16 {
return &v
}
// int32
// Int32Ptr takes an int32 literal and returns a pointer.
func Int32Ptr(v int32) *int32 {
return &v
}
// rune
// RunePtr takes a rune literal and returns a pointer.
func RunePtr(v rune) *rune {
return &v
}
// int64
// Int64Ptr takes an int64 literal and returns a pointer.
func Int64Ptr(v int64) *int64 {
return &v
}
// uint
// UintPtr takes a uint literal and returns a pointer.
func UintPtr(v uint) *uint {
return &v
}
// uint8
// Uint8 takes a uint8 literal and returns a pointer.
func Uint8Ptr(v uint8) *uint8 {
return &v
}
// byte
// BytePtr takes a byte literal and returns a pointer.
func BytePtr(v byte) *byte {
return &v
}
// uint16
// Uint16Ptr takes a uint16 literal and returns a pointer.
func Uint16Ptr(v uint16) *uint16 {
return &v
}
// uint32
// Uint32Ptr takes uint32 literal and returns a pointer.
func Uint32Ptr(v uint32) *uint32 {
return &v
}
// uint64
// Uint64Ptr takes uint64 literal and returns a pointer.
func Uint64Ptr(v uint64) *uint64 {
return &v
}
// float32
// Float32Ptr takes float32 literal and returns a pointer.
func Float32Ptr(v float32) *float32 {
return &v
}
// float64
// Float64Ptr takes a float64 literal and returns a pointer.
func Float64Ptr(v float64) *float64 {
return &v
}
// complex64
// Complex64Ptr takes a complex64 literal and returns a pointer.
func Complex64Ptr(v complex64) *complex64 {
return &v
}
// complex128
// Complex128Ptr takes a complex128 literal and returns a pointer.
func Complex128Ptr(v complex128) *complex128 {
return &v
}
// string
// StringPtr takes a string literal and returns a pointer.
func StringPtr(v string) *string {
return &v
}
// StrPtr is an alias of StringPtr.
func StrPtr(v string) *string {
return &v
}
// bool
// BoolPtr takes a bool literal and returns a pointer.
func BoolPtr(v bool) *bool {
return &v
}
@ -104,20 +109,31 @@ func BoolPtr(v bool) *bool {
* Error Handling
*/
// Check takes an error and prints it if it is not nil; but will continue.
func Check(err error) {
if err != nil {
fmt.Printf("%+v", err)
}
}
// CheckLog takes an error and a format function for leveraging a custom printer like a logger.
func CheckLog(err error, fn func(format string, a ...interface{})) {
if err != nil {
fn("%+v", err)
}
}
// CheckPanic takes an error and will panic if it is not nil.
func CheckPanic(err error) {
if err != nil {
panic(err)
}
}
// CheckExit takes an error and will print it and exit with status 1 if it is not nil.
func CheckExit(err error) {
if err != nil {
fmt.Printf("%+v", err)
os.Exit(1)
}
}