gsprotocol

package module
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 14 Imported by: 0

README

Test PkgGoDev

gsprotocol

Package gsprotocol provides the http.RoundTripper interface for Google Cloud Storage.

The typical use case is to register the "gs" protocol with a http.Transport, as in:

tr := &http.Transport{}
gs, err := gsprotocol.NewTransport(context.Background(), option.WithoutAuthentication())
if err != nil {
    // handle error
}
tr.RegisterProtocol("gs", gs)
c := &http.Client{Transport: tr}

resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt")
if err != nil {
    // handle error
}
defer resp.Body.Close()
// read resp.Body

Google Cloud Storage supports object versioning. To access the noncurrent version of an object, use a uri like gs://[BUCKET_NAME]/[OBJECT_NAME]#[GENERATION_NUMBER]. For example,

resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt#1587160158394554")

Documentation

Overview

Package gsprotocol provides the http.RoundTripper interface for Google Cloud Storage.

The typical use case is to register the "gs" protocol with a http.Transport, as in:

tr := &http.Transport{}
gs, err := gsprotocol.NewTransport(context.Background(), option.WithoutAuthentication())
if err != nil {
	// handle error
}
tr.RegisterProtocol("gs", gs)
c := &http.Client{Transport: tr}

resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt")
if err != nil {
	// handle error
}
defer resp.Body.Close()
// read resp.Body

Google Cloud Storage supports object versioning. To access the noncurrent version of an object, use a uri like gs://[BUCKET_NAME]/[OBJECT_NAME]#[GENERATION_NUMBER]. For example,

resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt#1587160158394554")

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport serving the Google Cloud Storage objects.

func NewTransport

func NewTransport(ctx context.Context, opts ...option.ClientOption) (*Transport, error)

NewTransport returns a new Transport.

Example
package main

import (
	"context"
	"io"
	"net/http"
	"os"

	"github.com/shogo82148/gsprotocol"
	"google.golang.org/api/option"
)

func main() {
	tr := &http.Transport{}
	gs, err := gsprotocol.NewTransport(context.Background(), option.WithoutAuthentication())
	if err != nil {
		panic(err)
	}
	tr.RegisterProtocol("gs", gs)
	c := &http.Client{Transport: tr}

	resp, err := c.Get("gs://shogo82148-gsprotocol/example.txt")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
		panic(err)
	}

}
Output:

Hello Google Cloud Storage!

func NewTransportWithClient

func NewTransportWithClient(client *storage.Client) *Transport

NewTransportWithClient returns a new Transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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