Giter VIP home page Giter VIP logo

go-sdk's Introduction

Codefresh SDK for Golang

Codefresh build status GoDoc Go Report Card

Start

go get -u github.com/codefresh-io/go-sdk

import (
    "fmt"
    "os"

    "github.com/codefresh-io/go-sdk/pkg/utils"
    "github.com/codefresh-io/go-sdk/pkg"
)

func main() {
    path := fmt.Sprintf("%s/.cfconfig", os.Getenv("HOME"))
    options, err := utils.ReadAuthContext(path, "")
    if err != nil {
        fmt.Println("Failed to read codefresh config file")
        panic(err)
    }
    clientOptions := codefresh.ClientOptions{Host: options.URL,
        Auth: codefresh.AuthOptions{Token: options.Token}}
    cf := codefresh.New(&clientOptions)
    pipelines, err := cf.Pipelines().List()
    if err != nil {
        fmt.Println("Failed to get Pipelines from Codefresh API")
        panic(err)
    }
    for _, p := range pipelines {
        fmt.Printf("Pipeline: %+v\n\n", p)
    }
}

This is not an official Codefresh project.

go-sdk's People

Contributors

andrii-codefresh avatar atgardner avatar daniel-codefresh avatar danielm-codefresh avatar elad-codefresh avatar eti-codefresh avatar funkycode avatar itai-codefresh avatar kim-codefresh avatar olegz-codefresh avatar oren-codefresh avatar pasha-codefresh avatar pchico83 avatar roi-codefresh avatar rotem-codefresh avatar yaroslav-codefresh avatar zarbis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-sdk's Issues

broken example in readme and no documentation

Hi,

The example in README is broken:

  1. import is incorrect - it should be utils and not util
  2. Codefresh New() func accepts &clientOptions and not AuthOptions.

Some more examples and documentation would be helpful

Allow extensibility by exposing the codefresh type

We've run into several cases where the current SDK doesn't implement certain endpoints. Unfortunately, since the API client (implemented by the codefresh type defined here) isn't exposed publicly, we have to build our own custom API client that does exactly the same things.

Would is be possible to expose the SDK's API client (type codefresh) so that it can be used to supplement missing endpoints?

Response body not being closed

The Go documentation states:

If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close. If the Body is not both read to EOF and closed, the Client's underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.
โ€” https://pkg.go.dev/net/http#Client.Do

However, the CodeFresh Go SDK is failing to close the response body in many instances.

For example, the workflow Get method makes a request (via (*codefresh).requestAPI) and then decodes it (via (*codefresh).decodeResponseInto), but never closes the response's Body.

Unfortunately, the way the code is currently structured will require that most calls to (*codefresh).requestAPI remember to defer resp.Body.Close(), so it's likely to continue to be missed in many places.

It may be worthwhile to extend *codefresh with an additional abstraction that fully consumes the body, including taking the responsibility of closing it. That way it won't continue to be missed. Perhaps the (*codefresh).decodeResponseInto and similar methods could be repurposed? I haven't dug through the code enough to know.

sdk doesn't work with recent golang

with golang 1.17.3:

$ go get -u github.com/codefresh-io/go-sdk
go: downloading gopkg.in/yaml.v2 v2.2.4
go: downloading github.com/olekukonko/tablewriter v0.0.5
go: downloading github.com/mattn/go-runewidth v0.0.13
go: downloading github.com/rivo/uniseg v0.2.0
go get: installing executables with 'go get' in module mode is deprecated.
	Use 'go install pkg@version' instead.
	For more information, see https://golang.org/doc/go-get-install-deprecation
	or run 'go help get' or 'go help install'.

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.