tuihub

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 20 Imported by: 3

README

TuiHub Go

TuiHub Client & Plugin helper for Go developers.

Installation

go get github.com/tuihub/tuihub-go

Getting Started

Client

package main

import (
	"context"
	"fmt"
	pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1"
	"github.com/tuihub/tuihub-go"
	"os"
)

func main() {
	ctx := context.Background()
	c, err := tuihub.LoginByPassword(ctx, "username", "password")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	information, err := c.GetServerInformation(ctx, &pb.GetServerInformationRequest{})
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println(information)
}

Plugin

package main

import (
	"context"
	"fmt"
	porter "github.com/tuihub/protos/pkg/librarian/porter/v1"
	"github.com/tuihub/tuihub-go"
	"os"
)

// go build -ldflags "-X main.version=x.y.z".
var (
	// version is the version of the compiled software.
	version string
)

// impl tuihub.Handler
type Handler struct{}

func main() {
	ctx := context.Background()
	plugin, err := tuihub.NewPorter(
		ctx,
		tuihub.PorterConfig{
			Name:           "plugin-name",
			Version:        version,
			GlobalName:     "YOUR_PROJECT_URL",
			FeatureSummary: &porter.PorterFeatureSummary{},
			Server:         tuihub.ServerConfig{},
		},
		Handler{},
	)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	err = plugin.Run()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(c *ServerConfig, service pb.LibrarianPorterServiceServer, logger log.Logger) *grpc.Server

func NewService

func NewService(p wrapper) pb.LibrarianPorterServiceServer

func WellKnownToString

func WellKnownToString(e protoreflect.Enum) string

func WithToken

func WithToken(ctx context.Context, token string) context.Context

Types

type ClientOption

type ClientOption func(*LibrarianClient)

func WithClientConsulConfig

func WithClientConsulConfig(config *capi.Config) ClientOption

func WithoutBackgroundRefresh

func WithoutBackgroundRefresh() ClientOption

type LibrarianClient

type LibrarianClient struct {
	pb.LibrarianSephirahServiceClient
	// contains filtered or unexported fields
}

func LoginByPassword

func LoginByPassword(
	ctx context.Context,
	username string,
	password string,
	options ...ClientOption,
) (*LibrarianClient, error)

func LoginByRefreshToken

func LoginByRefreshToken(
	ctx context.Context,
	refreshToken string,
	options ...ClientOption,
) (*LibrarianClient, error)

func (*LibrarianClient) RunBackgroundRefresh

func (c *LibrarianClient) RunBackgroundRefresh()

type Porter

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

func NewPorter

func NewPorter(ctx context.Context, config PorterConfig, handler Handler, options ...PorterOption) (*Porter, error)

func (*Porter) AsUser

func (p *Porter) AsUser(ctx context.Context, userID int64) (*LibrarianClient, error)

func (*Porter) Run

func (p *Porter) Run() error

func (*Porter) Stop

func (p *Porter) Stop() error

type PorterConfig

type PorterConfig struct {
	Name           string
	Version        string
	GlobalName     string
	FeatureSummary *porter.PorterFeatureSummary
}

type PorterOption

type PorterOption func(*Porter)

func WithLogger

func WithLogger(logger log.Logger) PorterOption

func WithPorterConsulConfig

func WithPorterConsulConfig(config *capi.Config) PorterOption

type ServerConfig

type ServerConfig struct {
	Network string
	Addr    string
	Timeout *time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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