Git Product home page Git Product logo

golf's Introduction

Golf Build Status Coverage Status GoDoc

Go List Fields (Golf) is a package for the Go language that makes it incredibly simple to get a list of fields from any type using the Field Output through Reflective Evaluation function, otherwise known as Fore:

type Person struct {
    Name string
}

p := &Person{"Batman"}

fields := golf.Fore("hero", p)

for k,v := range fields {
    fmt.Printf("%s=%v\n", k,v)
}

The above example will emit the following:

hero.Name=Batman

A simple example, the true power of Golf is in its configuration options.

golf's People

Contributors

akutz avatar spcomb avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

spcomb nooperpudd

golf's Issues

golf.fore panic on non-pointer struct values

With the following code in golf.fore:

	isaStruct := isStruct(val)
...
	if isaStruct && ef == nil {
...
	// get the value's type
	vt := reflect.ValueOf(val).Elem()

And some logging:

@@ -166,6 +166,8 @@ func fore(key string, val interface{}, bk9 map[string]interface{}) {
 
                ef = map[string]interface{}{}
 
+               log.Printf("fore key=%v val type=%T value=%#v kind=%v", key, val, val, reflect.ValueOf(val).Kind())
+
                // get the value's type
                vt := reflect.ValueOf(val).Elem()

This will panic if given a non-pointer struct value:

2017/03/07 15:54:17 fore key=error.inner val type=*vboxwebsrv.SOAPFault value=&vboxwebsrv.SOAPFault{XMLName:xml.Name{Space:"http://schemas.xmlsoap.org/soap/envelope/", Local:"Fault"}, Code:"SOAP-ENV:Client", String:"", Actor:"", Detail:""} kind=ptr
2017/03/07 15:54:17 fore key=error.inner.XMLName val type=xml.Name value=xml.Name{Space:"http://schemas.xmlsoap.org/soap/envelope/", Local:"Fault"} kind=struct
panic: reflect: call of reflect.Value.Elem on struct Value 

panic(0x1230140, 0xc4204002a0)
	/usr/local/go/src/runtime/panic.go:458 +0x243
reflect.Value.Elem(0x12c7560, 0xc4204001a0, 0x99, 0xc4204001a0, 0x99, 0x433891)
	/usr/local/go/src/reflect/value.go:734 +0x114
github.com/codedellemc/rexray/vendor/github.com/akutz/golf.fore(0xc420400240, 0x13, 0x12c7560, 0xc4204001a0, 0xc42045f800)
	/go/src/github.com/codedellemc/rexray/vendor/github.com/akutz/golf/golf.go:172 +0x666
github.com/codedellemc/rexray/vendor/github.com/akutz/golf.fore(0xc42040db70, 0xb, 0x12238a0, 0xc4202f69c0, 0xc42045f800)
	/go/src/github.com/codedellemc/rexray/vendor/github.com/akutz/golf/golf.go:217 +0x3f0
github.com/codedellemc/rexray/vendor/github.com/akutz/golf.fore(0x1478343, 0x5, 0x14109c0, 0xc4204000a0, 0xc42045f800)
	/go/src/github.com/codedellemc/rexray/vendor/github.com/akutz/golf/golf.go:217 +0x3f0
github.com/codedellemc/rexray/vendor/github.com/akutz/golf.Fore(0x1478343, 0x5, 0x14109c0, 0xc4204000a0, 0xc420124701)
	/go/src/github.com/codedellemc/rexray/vendor/github.com/akutz/golf/golf.go:146 +0xa8
github.com/codedellemc/rexray/vendor/github.com/akutz/golf/logrus.(*TextFormatter).printColored(0xc4202122c0, 0xc42021ac40, 0xc4202762c0, 0xc420400120, 0x2, 0x2, 0x1491b92, 0x19)
	/go/src/github.com/codedellemc/rexray/vendor/github.com/akutz/golf/logrus/text_formatter.go:132 +0x514
github.com/codedellemc/rexray/vendor/github.com/akutz/golf/logrus.(*TextFormatter).Format(0xc4202122c0, 0xc4202762c0, 0x0, 0xc4204f3148, 0x4f064e, 0x12c26e0, 0xc420057560)
	/go/src/github.com/codedellemc/rexray/vendor/github.com/akutz/golf/logrus/text_formatter.go:79 +0x760
github.com/codedellemc/rexray/vendor/github.com/Sirupsen/logrus.(*Entry).Reader(0xc4202762c0, 0xc4304e0a02, 0xc4202762c0, 0x0)

The error.inner.XMLName value is a xml.Name struct value, which cannot be dereferenced using reflect:Value.Elem:

It panics if v's Kind is not Interface or Ptr.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.