go-writer-github
GitHub API support for the go-writer Writer interface.
This package supersedes the go-whosonfirst-readwrite-github package.
Example
package main
import (
"context"
"flag"
"fmt"
"github.com/whosonfirst/go-writer"
_ "github.com/whosonfirst/go-writer-github"
"io/ioutil"
"strings"
"time"
)
func main() {
owner := "example"
repo := "example-repo"
access_token := "s33kret"
branch := "example"
ctx := context.Background()
source := fmt.Sprintf("githubapi://%s/%s?access_token=%s&branch=%s", owner, repo, access_token, branch)
wr, _ := writer.NewWriter(ctx, source)
now := time.Now()
msg := fmt.Sprintf("This is a test: %v", now)
br := strings.NewReader(msg)
fh := ioutil.NopCloser(br)
wr.Write(ctx, "TEST.md", fh)
}
Error handling has been omitted for brevity.
URIs
The URI structure for go-writer-github (API) writers is:
| Component |
Value |
Notes |
| Scheme |
githubapi |
|
| Host |
string |
A valid GitHub owner or organization |
| Path |
string |
A valid GitHub respository |
| Query |
|
described below |
The following query parameters are supported for go-writer-github writers:
| Name |
Value |
Required |
Notes |
| access_token |
string |
yes |
A valid GitHub API access token |
| branch |
string |
no |
A valid Git repository branch. Default is master. |
| new |
string |
no |
A valid string for formatting new file commit messages. Default is Created %s. |
| update |
string |
no |
A valid string for formatting updated file commit messages. Default is Updated %s. |
| retry-on-ratelimit |
boolean (string) |
no |
If true and the writer encounters a GitHub rate-limit error trying to write data it will sleep until the "reset" time (published by GitHub) and retry the write operation. |
| retry-on-conflict |
boolean (string) |
no |
If true and the writer encounters a GitHub 409 Conflict error trying to write data it will keep trying (by refreshing the current hash) until it succeeds, with the limits of the ?max-retry-attempts flag. |
| max-retry-attempts |
int |
no |
Default is 10. If <=0 then checks on the maximum number of retry attempts will be disabled. |
See also