2021-10-03 00:27:43 +02:00
|
|
|
# woodpecker-go
|
2019-04-06 21:32:14 +02:00
|
|
|
|
|
|
|
```Go
|
|
|
|
import (
|
2021-10-03 00:27:43 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
2019-04-06 21:32:14 +02:00
|
|
|
"golang.org/x/oauth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
|
2021-10-03 00:27:43 +02:00
|
|
|
host = "http://woodpecker.company.tld"
|
2019-04-06 21:32:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// create an http client with oauth authentication.
|
|
|
|
config := new(oauth2.Config)
|
2021-10-08 18:35:56 +02:00
|
|
|
authenticator := config.Client(
|
2019-04-06 21:32:14 +02:00
|
|
|
oauth2.NoContext,
|
|
|
|
&oauth2.Token{
|
|
|
|
AccessToken: token,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2021-10-03 00:27:43 +02:00
|
|
|
// create the woodpecker client with authenticator
|
2021-10-08 18:35:56 +02:00
|
|
|
client := woodpecker.NewClient(host, authenticator)
|
2019-04-06 21:32:14 +02:00
|
|
|
|
|
|
|
// gets the current user
|
|
|
|
user, err := client.Self()
|
|
|
|
fmt.Println(user, err)
|
|
|
|
|
|
|
|
// gets the named repository information
|
2021-10-03 00:27:43 +02:00
|
|
|
repo, err := client.Repo("woodpecker-ci", "woodpecker")
|
2019-04-06 21:32:14 +02:00
|
|
|
fmt.Println(repo, err)
|
|
|
|
}
|
|
|
|
```
|