aip

package module
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 0 Imported by: 0

README

AIP Go

Go SDK for implementing Google API Improvement Proposals (AIP).

Documentation

See https://aip.dev for the full AIP documentation.

Installing

$ go get -u go.einride.tech/aip

Examples

AIP-132 (Standard method: List)
package examplelibrary

import (
	"context"

	"go.einride.tech/aip/pagination"
	"google.golang.org/genproto/googleapis/example/library/v1"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

func (s *Server) ListShelves(
	ctx context.Context,
	request *library.ListShelvesRequest,
) (*library.ListShelvesResponse, error) {
	// Handle request constraints.
	const (
		maxPageSize     = 1000
		defaultPageSize = 100
	)
	switch {
	case request.PageSize < 0:
		return nil, status.Errorf(codes.InvalidArgument, "page size is negative")
	case request.PageSize == 0:
		request.PageSize = defaultPageSize
	case request.PageSize > maxPageSize:
		request.PageSize = maxPageSize
	}
	// Use pagination.PageToken for offset-based page tokens.
	pageToken, err := pagination.ParsePageToken(request)
	if err != nil {
		return nil, status.Errorf(codes.InvalidArgument, "invalid page token")
	}
	// Query the storage.
	result, err := s.Storage.ListShelves(ctx, &ListShelvesQuery{
		Offset:   pageToken.Offset,
		PageSize: request.GetPageSize(),
	})
	if err != nil {
		return nil, err
	}
	// Build the response.
	response := &library.ListShelvesResponse{
		Shelves: result.Shelves,
	}
	// Set the next page token.
	if result.HasNextPage {
		response.NextPageToken = pageToken.Next(request).String()
	}
	// Respond.
	return response, nil
}

Documentation

Overview

Package aip provides primitives for implementing API Improvement Proposals (AIP).

Directories

Path Synopsis
examples
Package fieldbehavior provides primitives for implementing AIP fieldbehavior annotations.
Package fieldbehavior provides primitives for implementing AIP fieldbehavior annotations.
Package fieldmask provides primitives for implementing AIP field mask functionality.
Package fieldmask provides primitives for implementing AIP field mask functionality.
Package filtering provides primitives for implementing AIP filtering.
Package filtering provides primitives for implementing AIP filtering.
Package ordering provides primitives for implementing AIP ordering.
Package ordering provides primitives for implementing AIP ordering.
Package pagination provides primitives for implementing AIP pagination.
Package pagination provides primitives for implementing AIP pagination.
proto
reflect
aipreflect
Package aipreflect provides primitives to manipulate AIP annotations and descriptors.
Package aipreflect provides primitives to manipulate AIP annotations and descriptors.
Package resourcename implements simple functions to manipulate UTF-8 encoded AIP resource names.
Package resourcename implements simple functions to manipulate UTF-8 encoded AIP resource names.
tools
Package validation provides primitives for validating proto messages and gRPC requests.
Package validation provides primitives for validating proto messages and gRPC requests.

Jump to

Keyboard shortcuts

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