Skip to content

kmikiy/helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

go get github.com/kmikiy/helper/...

Example

ptr

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

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)
}

About

Simple helper library for golang pointers & built-in types

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages