writer

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2022 License: BSD-3-Clause Imports: 14 Imported by: 1

README

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-onrate-limit boolean (string) 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.

See also

Documentation

Overview

package writer

Index

Constants

View Source
const DEFAULT_BRANCH string = "main"

Variables

This section is empty.

Functions

func NewGitHubAPIWriter

func NewGitHubAPIWriter(ctx context.Context, uri string) (wof_writer.Writer, error)

Types

type GitHubAPIWriter

type GitHubAPIWriter struct {
	wof_writer.Writer
	// contains filtered or unexported fields
}

func (*GitHubAPIWriter) Write

func (wr *GitHubAPIWriter) Write(ctx context.Context, uri string, fh io.ReadSeeker) (int64, error)

func (*GitHubAPIWriter) WriterURI added in v0.3.0

func (wr *GitHubAPIWriter) WriterURI(ctx context.Context, key string) string

type GitHubAPIWriterCommitTemplates

type GitHubAPIWriterCommitTemplates struct {
	New    string
	Update string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL