scottdware / go-bigip

A Go package that interacts with F5 BIG-IP systems using the REST API.
MIT License
109 stars 119 forks source link

f5.ServerSSLProfiles panic runtime error: invalid memory address or nil pointer dereference #121

Closed yangmingbai closed 3 years ago

yangmingbai commented 3 years ago

Hello!

when i run f5.ServerSSLProfiles() I got a panic error.

json: cannot unmarshal string into Go struct field ServerSSLProfile.items.tmOptions of type []string
panic: runtime error: invalid memory address or nil pointer dereference
scottdware commented 3 years ago

Can you post your entire code?

yangmingbai commented 3 years ago

well ,now i know because the f5 devices version is different, i'll get different field type,so it causes JSON parse error, for example:

type ServerSSLProfile struct{
    TmOptions                    []string `json:"tmOptions,omitempty"`  
}
type Node struct {
  FQDN            struct    `json:"fqdn,omitempty"`
}

in this function:

func (b *BigIP) getForEntity(e interface{}, path ...string) (error, bool) {
    req := &APIRequest{
        Method:      "get",
        URL:         b.iControlPath(path),
        ContentType: "application/json",
    }

    resp, err := b.APICall(req)
    if err != nil {
        var reqError RequestError
        json.Unmarshal(resp, &reqError)
        if reqError.Code == 404 {
            return nil, false
        }
        return err, false
    }
    err = json.Unmarshal(resp, e)
    if err != nil {
        return err, false
    }

    return nil, true
}

thanks!

scottdware commented 3 years ago

Sure thing :)