github.com/go-chef/chef@v0.30.1/README.md (about)

     1  [![Stories in Ready](https://badge.waffle.io/go-chef/chef.png?label=ready&title=Ready)](https://waffle.io/go-chef/chef)
     2  [![Build Status](https://app.wercker.com/status/9cfd4b53ea24e0894904067f283e4cf8/s "wercker status")](https://app.wercker.com/project/bykey/9cfd4b53ea24e0894904067f283e4cf8)
     3  [![Coverage Status](https://coveralls.io/repos/go-chef/chef/badge.png?branch=master)](https://coveralls.io/r/go-chef/chef?branch=master)
     4  
     5  # Chef Server API Client Library in Golang
     6  This is a Library that you can use to write tools to interact with the chef server. 
     7  
     8  ## Install
     9   
    10      go get github.com/go-chef/chef
    11  
    12  ## Test
    13    
    14      go get -t github.com/go-chef/chef
    15      go test -v github.com/go-chef/chef
    16      test_chef_server: kitchen verify  # integration tests
    17  
    18  ## SSL
    19  
    20    If you run into an SSL verification problem when trying to connect to a ssl server with self signed certs set up your config object with `SkipSSL: true`
    21  
    22  ## Usage
    23  This example is setting up a basic client that you can use to interact with all the service endpoints (clients, nodes, cookbooks, etc. At [@chefapi](https://docs.chef.io/api_chef_server.html))
    24  More usage examples can be found in the [examples](examples) directory.
    25  
    26  ```go
    27  package main
    28  
    29  import (
    30  	"fmt"
    31  	"os"
    32  	"github.com/go-chef/chef"
    33  )
    34  
    35  func main() {
    36  	// read a client key
    37  	key, err := os.ReadFile("key.pem")
    38  	if err != nil {
    39  		fmt.Println("Couldn't read key.pem:", err)
    40  		os.Exit(1)
    41  	}
    42  
    43  	// build a client
    44  	client, err := chef.NewClient(&chef.Config{
    45  		Name: "foo",
    46  		Key:  string(key),
    47  		// goiardi is on port 4545 by default. chef-zero is 8889
    48  		BaseURL: "http://localhost:4545",
    49  	})
    50  	if err != nil {
    51  		fmt.Println("Issue setting up client:", err)
    52  	}
    53  
    54  	// List Cookbooks
    55  	cookList, err := client.Cookbooks.List()
    56  	if err != nil {
    57  		fmt.Println("Issue listing cookbooks:", err)
    58  	}
    59  
    60  	// Print out the list
    61  	fmt.Println(cookList)
    62  }
    63  ```
    64  
    65  ## Chef API Error Status
    66  To get the error status and error message returned from calls to the Chef API Server
    67  you can use ChefError to unwind the ErrorResponse and access the original http error.
    68  These methods are available to get specific information from the the error.
    69  
    70  * Error() returns a formatted error message with the URL and status code.
    71  * StatusCode() returns the original return status code.
    72  * StatusMsg() returns the error message extracted from the error message body.
    73  * StatusText() returns the returned error message body, usually JSON.
    74  * StatusMethod() returns the name of the method used for the request.
    75  * StatusURL() returns the URL object used for the request.
    76  
    77  ## CONTRIBUTING
    78  
    79  If you feel like contributing, great! Just fork the repo, make your
    80  improvements, and submit a pull request. Tests would, of course, be appreciated.
    81  Adding tests where there are no tests currently would be even more appreciated.
    82  At least, though, try and not break anything worse than it is. Test coverage has
    83  improved, but is still an ongoing concern.
    84  
    85  ## AUTHORS
    86  
    87  |               |                                                |
    88  |:--------------|:-----------------------------------------------|
    89  |Jesse Nelson   |[@spheromak](https://github.com/spheromak)
    90  |AJ Christensen |[@fujin](https://github.com/fujin)
    91  |Brad Beam      |[@bradbeam](https://github.com/bradbeam)
    92  |Kraig Amador   |[@bigkraig](https://github.com/bigkraig)
    93  |Mark Gibbons   |[@mark](https://github.com/markgibbons)
    94  
    95  ## COPYRIGHT
    96  
    97  Copyright 2013-2014, Jesse Nelson
    98  
    99  ## LICENSE
   100  
   101  Like many Chef ecosystem programs, go-chef/chef is licensed under the Apache 2.0
   102  License. See the LICENSE file for details.
   103  
   104  Chef is copyright (c) 2008-2014 Chef, Inc. and its various contributors.
   105  
   106  Thanks go out to the fine folks of Opscode and the Chef community for all their
   107  hard work.