First pass

This commit is contained in:
Diego Fernando Carrión 2021-08-21 15:21:28 +02:00
parent 6ec8f42491
commit 96b9001b80
4 changed files with 129 additions and 1 deletions

View File

@ -1,3 +1,5 @@
# sugar
Syntactic Sugar for Golang
## Syntactic Sugar for Golang
This package provides some convenience functions that help keep code clean.

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitlab.com/CRThaze/sugar
go 1.17

0
go.sum Normal file
View File

123
sugar.go Normal file
View File

@ -0,0 +1,123 @@
// Package sugar
package sugar
import "fmt"
/*
* Literal Addressers
*/
// int
func IntPtr(v int) *int {
return &v
}
// int8
func Int8Ptr(v int8) *int8 {
return &v
}
// int16
func Int16Ptr(v int16) *int16 {
return &v
}
// int32
func Int32Ptr(v int32) *int32 {
return &v
}
// rune
func RunePtr(v rune) *rune {
return &v
}
// int64
func Int64Ptr(v int64) *int64 {
return &v
}
// uint
func UintPtr(v uint) *uint {
return &v
}
// uint8
func Uint8Ptr(v uint8) *uint8 {
return &v
}
// byte
func BytePtr(v byte) *byte {
return &v
}
// uint16
func Uint16Ptr(v uint16) *uint16 {
return &v
}
// uint32
func Uint32Ptr(v uint32) *uint32 {
return &v
}
// uint64
func Uint64Ptr(v uint64) *uint64 {
return &v
}
// float32
func Float32Ptr(v float32) *float32 {
return &v
}
// float64
func Float64Ptr(v float64) *float64 {
return &v
}
// complex64
func Complex64Ptr(v complex64) *complex64 {
return &v
}
// complex128
func Complex128Ptr(v complex128) *complex128 {
return &v
}
// string
func StringPtr(v string) *string {
return &v
}
func StrPtr(v string) *string {
return &v
}
// bool
func BoolPtr(v bool) *bool {
return &v
}
/*
* Error Handling
*/
func Check(err error) {
if err != nil {
fmt.Printf("%+v", err)
}
}
func CheckLog(err error, fn func(format string, a ...interface{})) {
if err != nil {
fn("%+v", err)
}
}
func CheckPanic(err error) {
if err != nil {
panic(err)
}
}