https://github.com/kmikiy/helper
Simple helper library for golang pointers & built-in types
https://github.com/kmikiy/helper
builtin golang golang-library golang-package pointers primitives
Last synced: 5 months ago
JSON representation
Simple helper library for golang pointers & built-in types
- Host: GitHub
- URL: https://github.com/kmikiy/helper
- Owner: kmikiy
- Created: 2019-01-15T19:49:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-15T19:51:46.000Z (over 7 years ago)
- Last Synced: 2025-08-14T15:34:12.799Z (10 months ago)
- Topics: builtin, golang, golang-library, golang-package, pointers, primitives
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# helper
helper consists of two packages `ptr` & `labaled`.
`ptr` makes it easy to create pointers of common built-in types. `labeled` is useful for adding additional information when using built-in types.
## Installation
```sh
go get github.com/kmikiy/helper/...
```
## Example
### ptr
```go
import (
"log"
"time"
"github.com/kmikiy/helper/ptr"
)
type Subscription struct {
Name string
SubscribedAt *time.Time
}
func main() {
// with "github.com/kmikiy/helper/ptr"
sub := Subscription{
Name: "pro",
SubscribedAt: ptr.Time(time.Now()),
}
log.Printf("sub: %#+v\n", sub)
// without "github.com/kmikiy/helper/ptr"
now := time.Now()
sub := Subscription{
Name: "pro",
SubscribedAt: &now,
}
log.Printf("sub: %#+v\n", sub)
}
```
### labeled
```go
import (
"log"
"time"
l "github.com/kmikiy/helper/labeled"
)
func fetch(limit int, offset int) {
log.Printf("limit: %#+v\n", offset)
log.Printf("offset: %#+v\n", offset)
}
func main() {
// with "github.com/kmikiy/helper/labeled"
fetch(l.Int("limit", 1), l.Int("offset", 20))
// without "github.com/kmikiy/helper/labeled"
fetch(1, 20)
}
```