Last active
June 22, 2017 22:18
-
-
Save j-griffith/6dff1638ec7dfd7d233adde81ce7b3d5 to your computer and use it in GitHub Desktop.
Example usage of new error type in golang-sfapi (test by modifying element:ListAccounts and providing a bogus method-name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
log "github.com/Sirupsen/logrus" | |
"github.com/solidfire/solidfire-sdk-golang/sfapi" | |
"github.com/solidfire/solidfire-sdk-golang/sftypes" | |
"strings" | |
) | |
func apiErrToMap(apiErr string) (map[string]string, error) { | |
m := make(map[string]string) | |
items := strings.Split(apiErr, ",") | |
for _, entry := range items { | |
pair := strings.Split(entry, ":") | |
m[pair[0]] = pair[1] | |
} | |
return m, nil | |
} | |
func main() { | |
log.SetLevel(log.DebugLevel) | |
sfClient, err := sfapi.Create("10.117.36.101", "admin", "admin", "8.0", 443, 30) | |
if err != nil { | |
fmt.Printf("Received an error: %+v", err) | |
} | |
req := sftypes.ListAccountsRequest{} | |
_, err = sfClient.ListAccounts(req) | |
if err != nil { | |
switch t := err.(type) { | |
default: | |
fmt.Printf("Booo... we're dead: %+v\n", err) | |
case *sfapi.ReqErr: | |
fmt.Printf("Name: %+v\n", t.Name()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment