Skip to content

Instantly share code, notes, and snippets.

@krmgns
Last active November 16, 2015 00:54
Show Gist options
  • Save krmgns/51897a70f98c4d6e3bc9 to your computer and use it in GitHub Desktop.
Save krmgns/51897a70f98c4d6e3bc9 to your computer and use it in GitHub Desktop.
Go tools.
import "fmt"
func Type(args ...interface{}) string {
return fmt.Sprintf("%T", args[0])
}
func Dump(args ...interface{}) {
fmt.Println(args...)
}
func Dumps(args ...interface{}) {
var format string
for _, arg := range args {
_ = arg // silence..
format += "%+v "
}
fmt.Printf("%s\n", fmt.Sprintf(format, args...))
}
func Dumpf(format string, args ...interface{}) {
if format == "" {
for _, arg := range args {
_ = arg // silence..
format += "%+v "
}
}
fmt.Printf("%s\n", fmt.Sprintf(format, args...))
}
/*** static method ***/
// http.go
package http
type Stream struct {
headers map[string]string
body interface{}
Request struct {
method string
uri string
}
Response struct {
statusCode int8
statusText string
}
}
// no pointer like (s *Stream)
func (Stream) Init() *Stream {
return new(Stream)
}
// main.go
import http "./http"
func main() {
// <PACKAGE>.<STRUCT><brackets{}>.<INIT>
var stream = http.Stream{}.Init()
u.Dumps(stream)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment