template

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SingleApp = `package app

import (
	"context"

	"{{.Dir}}/pkg/runtime/inject"
	"github.com/vine-io/vine"

	"{{.Dir}}/pkg/biz"
)

func init() {
	inject.ProvidePanic(new({{.Name}}))
}

type {{title .Name}} interface {
	Init() error
	Call(ctx context.Context, name string) (string, error)
	Stream()
	PingPong()
}

var _ {{title .Name}} = (*{{.Name}})(nil)

type {{.Name}} struct {
	vine.Service ` + "`inject:\"\"`" + `

	Caller biz.Caller ` + "`inject:\"\"`" + `
}

func (s *{{.Name}}) Init() error {
	return nil
}

func (s *{{.Name}}) Call(ctx context.Context, name string) (string, error) {
	return s.Caller.CallS(ctx, name)
}

func (s *{{.Name}}) Stream() {
	panic("implement me")
}

func (s *{{.Name}}) PingPong() {
	panic("implement me")
}
`

	ClusterApp = `package app

import (
	"context"

	"{{.Dir}}/pkg/runtime/inject"
	"github.com/vine-io/vine"

	"{{.Dir}}/pkg/{{.Name}}/biz"
)

func init() {
	inject.ProvidePanic(new({{.Name}}))
}

type {{title .Name}} interface {
	Init() error
	Call(ctx context.Context, name string) (string, error)
	Stream()
	PingPong()
}

var _ {{title .Name}} = (*{{.Name}})(nil)

type {{.Name}} struct {
	vine.Service ` + "`inject:\"\"`" + `

	Caller biz.Caller ` + "`inject:\"\"`" + `
}

func (s *{{.Name}}) Init() error {
	return nil
}

func (s *{{.Name}}) Call(ctx context.Context, name string) (string, error) {
	return s.Caller.CallS(ctx, name)
}

func (s *{{.Name}}) Stream() {
	panic("implement me")
}

func (s *{{.Name}}) PingPong() {
	panic("implement me")
}
`
)
View Source
var (
	SingleCMD = `package main

import (
	"{{.Dir}}/pkg"
)

func main() {
	pkg.Run()
}
`

	ClusterCMD = `package main

import (
	"{{.Dir}}/pkg/{{.Name}}"
)

func main() {
	{{.Name}}.Run()
}
`
)
View Source
var (
	ConfSRV = `#[server]
SERVER_NAME="{{.Name}}"
SERVER_ADDRESS="localhost:11401"
`

	ConfGateway = `#[server]
SERVER_NAME="{{.Name}}"
SERVER_ADDRESS="localhost:80"
`
)
View Source
var (
	DockerSRV = `` /* 126-byte string literal not displayed */

	DockerWEB = `FROM alpine
ADD html /html
ADD {{.Name}} /{{.Name}}
WORKDIR /
ENTRYPOINT [ "/{{.Name}}" ]
`
)
View Source
var (
	SingleEntry = `` /* 241-byte string literal not displayed */

	ClusterEntry = `` /* 263-byte string literal not displayed */

	GatewayEntry = `` /* 3308-byte string literal not displayed */

)
View Source
var (
	RepoHandler = `` /* 172-byte string literal not displayed */

	CacheHandler = `package cache
`
)
View Source
var (
	SingleINF = `package interfaces

import (
	"context"

	"github.com/vine-io/vine"
	log "github.com/vine-io/vine/lib/logger"
	verrs "github.com/vine-io/vine/lib/errors"

	"{{.Dir}}/pkg/runtime"
	"{{.Dir}}/pkg/runtime/inject"
	"{{.Dir}}/pkg/app"

	pb "{{.Dir}}/api/service/{{.Group}}/{{.Version}}"
)

type {{title .Name}}API struct{
	vine.Service

	H app.{{title .Name}} ` + "`inject:\"\"`" + `
}

// Call is a single request handler called via client.Call or the generated client code
func (s *{{title .Name}}API) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) (err error) {
	if err = req.Validate(); err != nil {
		return verrs.BadRequest(s.Name(), err.Error())
	}
	rsp.Msg, err = s.H.Call(ctx, req.Name)
	return
}

// Stream is a server side stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) Stream(ctx context.Context, req *pb.StreamingRequest, stream pb.{{title .Name}}Service_StreamStream) error {
	log.Infof("Received {{title .Name}}.Stream request with count: %d", req.Count)

	// TODO: Validate
	s.H.Stream()
	// FIXME: fix stream method

	for i := 0; i < int(req.Count); i++ {
		log.Infof("Responding: %d", i)
		if err := stream.Send(&pb.StreamingResponse{
			Count: int64(i),
		}); err != nil {
			return err
		}
	}

	return nil
}

// PingPong is a bidirectional stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) PingPong(ctx context.Context, stream pb.{{title .Name}}Service_PingPongStream) error {
	// TODO: Validate
	s.H.PingPong()
	// FIXME: fix stream pingpong

	for {
		req, err := stream.Recv()
		if err != nil {
			return err
		}
		log.Infof("Got ping %v", req.Stroke)
		if err := stream.Send(&pb.Pong{Stroke: req.Stroke}); err != nil {
			return err
		}
	}
}

func (s *{{title .Name}}API) Init() error {
	var err error

	opts := []vine.Option{
		vine.Name(runtime.{{title .Name}}Name),
		vine.Id(runtime.{{title .Name}}Id),
		vine.Version(runtime.GetVersion()),
		vine.Metadata(map[string]string{
			"namespace": runtime.Namespace,
		}),
	}

	s.Service.Init(opts...)

	if err = inject.Provide(s.Service, s.Client(), s); err != nil {
		return err
	}

	// TODO: inject more objects

	if err = inject.Populate(); err != nil {
		return err
	}

	if err = s.H.Init(); err != nil {
		return err
	}

	if err = pb.Register{{title .Name}}ServiceHandler(s.Service.Server(), s); err != nil {
		return err
	}

	return err
}

func New() *{{title .Name}}API {
	srv := vine.NewService()
	return &{{title .Name}}API{
		Service: srv,
	}
}
`

	SingleINFWithAPI = `package interfaces

import (
	"context"

	"github.com/vine-io/vine"
	log "github.com/vine-io/vine/lib/logger"
	verrs "github.com/vine-io/vine/lib/errors"

	"{{.Dir}}/pkg/runtime"
	"{{.Dir}}/pkg/runtime/inject"
	"{{.Dir}}/pkg/app"
	pb "{{.Dir}}/api/service/{{.Group}}/{{.Version}}"
)

type {{title .Name}}API struct{
	vine.Service

	H app.{{title .Name}} ` + "`inject:\"\"`" + `
}

// Call is a single request handler called via client.Call or the generated client code
func (s *{{title .Name}}API) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) (err error) {
	if err = req.Validate(); err != nil {
		return verrs.BadRequest(s.Name(), err.Error())
	}
	rsp.Msg, err = s.H.Call(ctx, req.Name)
	return
}

// Stream is a server side stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) Stream(ctx context.Context, req *pb.StreamingRequest, stream pb.{{title .Name}}Service_StreamStream) error {
	log.Infof("Received {{title .Name}}.Stream request with count: %d", req.Count)

	// TODO: Validate
	s.H.Stream()
	// FIXME: fix stream method

	for i := 0; i < int(req.Count); i++ {
		log.Infof("Responding: %d", i)
		if err := stream.Send(&pb.StreamingResponse{
			Count: int64(i),
		}); err != nil {
			return err
		}
	}

	return nil
}

// PingPong is a bidirectional stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) PingPong(ctx context.Context, stream pb.{{title .Name}}Service_PingPongStream) error {
	// TODO: Validate
	s.H.PingPong()
	// FIXME: fix stream pingpong

	for {
		req, err := stream.Recv()
		if err != nil {
			return err
		}
		log.Infof("Got ping %v", req.Stroke)
		if err := stream.Send(&pb.Pong{Stroke: req.Stroke}); err != nil {
			return err
		}
	}
}

func (s *{{title .Name}}API) Init() error {
	var err error

	opts := []vine.Option{
		vine.Name(runtime.{{title .Name}}Name),
		vine.Id(runtime.{{title .Name}}Id),
		vine.Version(runtime.GetVersion()),
		vine.Metadata(map[string]string{
			"namespace": runtime.Namespace,
		}),
	}

	s.Service.Init(opts...)

	if err = inject.Provide(s.Service, s.Client(), s); err != nil {
		return err
	}

	// TODO: inject more objects

	if err = inject.Populate(); err != nil {
		return err
	}

	if err = s.H.Init(); err != nil {
		return err
	}

	if err = pb.Register{{title .Name}}ServiceHandler(s.Service.Server(), s); err != nil {
		return err
	}

	return err
}

func New() *{{title .Name}}API {
	srv := vine.NewService()
	return &{{title .Name}}API{
		Service: srv,
	}
}
`

	ClusterINF = `package interfaces

import (
	"context"

	"github.com/vine-io/vine"
	log "github.com/vine-io/vine/lib/logger"
	verrs "github.com/vine-io/vine/lib/errors"

	"{{.Dir}}/pkg/runtime"
	"{{.Dir}}/pkg/{{.Name}}/app"
	"{{.Dir}}/pkg/runtime/inject"
	pb "{{.Dir}}/api/service/{{.Group}}/{{.Version}}"
)

type {{title .Name}}API struct{
	vine.Service

	H app.{{title .Name}} ` + "`inject:\"\"`" + `
}

// Call is a single request handler called via client.Call or the generated client code
func (s *{{title .Name}}API) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) (err error) {
	if err = req.Validate(); err != nil {
		return verrs.BadRequest(s.Name(), err.Error())
	}
	rsp.Msg, err = s.H.Call(ctx, req.Name)
	return
}

// Stream is a server side stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) Stream(ctx context.Context, req *pb.StreamingRequest, stream pb.{{title .Name}}Service_StreamStream) error {
	log.Infof("Received {{title .Name}}.Stream request with count: %d", req.Count)

	// TODO: Validate
	s.H.Stream()
	// FIXME: fix stream method

	for i := 0; i < int(req.Count); i++ {
		log.Infof("Responding: %d", i)
		if err := stream.Send(&pb.StreamingResponse{
			Count: int64(i),
		}); err != nil {
			return err
		}
	}

	return nil
}

// PingPong is a bidirectional stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) PingPong(ctx context.Context, stream pb.{{title .Name}}Service_PingPongStream) error {
	// TODO: Validate
	s.H.PingPong()
	// FIXME: fix stream pingpong

	for {
		req, err := stream.Recv()
		if err != nil {
			return err
		}
		log.Infof("Got ping %v", req.Stroke)
		if err := stream.Send(&pb.Pong{Stroke: req.Stroke}); err != nil {
			return err
		}
	}
}

func (s *{{title .Name}}API) Init() error {
	var err error

	opts := []vine.Option{
		vine.Name(runtime.{{title .Name}}Name),
		vine.Id(runtime.{{title .Name}}Id),
		vine.Version(runtime.GetVersion()),
		vine.Metadata(map[string]string{
			"namespace": runtime.Namespace,
		}),
	}

	s.Service.Init(opts...)

	if err = inject.Provide(s.Service, s.Client(), s); err != nil {
		return err
	}

	// TODO: inject more objects

	if err = inject.Populate(); err != nil {
		return err
	}

	if err = s.H.Init(); err != nil {
		return err
	}

	if err = pb.Register{{title .Name}}ServiceHandler(s.Service.Server(), s); err != nil {
		return err
	}

	return err
}

func New() *{{title .Name}}API {
	srv := vine.NewService()
	return &{{title .Name}}API{
		Service: srv,
	}
}
`

	ClusterINFWithAPI = `package interfaces

import (
	"context"

	"github.com/vine-io/vine"
	log "github.com/vine-io/vine/lib/logger"
	verrs "github.com/vine-io/vine/lib/errors"

	"{{.Dir}}/pkg/runtime"
	"{{.Dir}}/pkg/{{.Name}}/app"
	"{{.Dir}}/pkg/runtime/inject"
	pb "{{.Dir}}/api/service/{{.Group}}/{{.Version}}"
)

type {{title .Name}}API struct{
	vine.Service

	H app.{{title .Name}} ` + "`inject:\"\"`" + `
}

// Call is a single request handler called via client.Call or the generated client code
func (s *{{title .Name}}API) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) (err error) {
	if err = req.Validate(); err != nil {
		return verrs.BadRequest(s.Name(), err.Error())
	}
	rsp.Msg, err = s.H.Call(ctx, req.Name)
	return
}

// Stream is a server side stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) Stream(ctx context.Context, req *pb.StreamingRequest, stream pb.{{title .Name}}Service_StreamStream) error {
	log.Infof("Received {{title .Name}}.Stream request with count: %d", req.Count)

	// TODO: Validate
	s.H.Stream()
	// FIXME: fix stream method

	for i := 0; i < int(req.Count); i++ {
		log.Infof("Responding: %d", i)
		if err := stream.Send(&pb.StreamingResponse{
			Count: int64(i),
		}); err != nil {
			return err
		}
	}

	return nil
}

// PingPong is a bidirectional stream handler called via client.Stream or the generated client code
func (s *{{title .Name}}API) PingPong(ctx context.Context, stream pb.{{title .Name}}Service_PingPongStream) error {
	// TODO: Validate
	s.H.PingPong()
	// FIXME: fix stream pingpong

	for {
		req, err := stream.Recv()
		if err != nil {
			return err
		}
		log.Infof("Got ping %v", req.Stroke)
		if err := stream.Send(&pb.Pong{Stroke: req.Stroke}); err != nil {
			return err
		}
	}
}

func (s *{{title .Name}}API) Init() error {
	var err error

	opts := []vine.Option{
		vine.Name(runtime.{{title .Name}}Name),
		vine.Id(runtime.{{title .Name}}Id),
		vine.Version(runtime.GetVersion()),
		vine.Metadata(map[string]string{
			"namespace": runtime.Namespace,
		}),
	}

	s.Service.Init(opts...)

	if err = inject.Provide(s.Service, s.Client(), s); err != nil {
		return err
	}

	// TODO: inject more objects

	if err = inject.Populate(); err != nil {
		return err
	}

	if err = s.H.Init(); err != nil {
		return err
	}

	if err = pb.Register{{title .Name}}ServiceHandler(s.Service.Server(), s); err != nil {
		return err
	}

	return err
}

func New() *{{title .Name}}API {
	srv := vine.NewService()
	return &{{title .Name}}API{
		Service: srv,
	}
}
`
)
View Source
var (
	SingleMakefile = `` /* 666-byte string literal not displayed */

	ClusterMakefile = `` /* 666-byte string literal not displayed */

	GenerateFile = `package main
//go:generate make proto
`
)
View Source
var (
	ProtoType = `` /* 333-byte string literal not displayed */

	ProtoSRV = `` /* 782-byte string literal not displayed */

	ProtoNew = `` /* 465-byte string literal not displayed */

)
View Source
var (
	Doc = `` /* 675-byte string literal not displayed */

	Inject = `` /* 1154-byte string literal not displayed */

)
View Source
var (
	DomainSRV = `` /* 350-byte string literal not displayed */

)
View Source
var (
	GitIgnore = `.idea

.DS_Store

testdata

*.db

_output

.vscode
*.pb.*.go
`
)
View Source
var (
	HTMLWEB = `` /* 2930-byte string literal not displayed */

)
View Source
var (
	Module = `` /* 156-byte string literal not displayed */

)
View Source
var (
	Readme = `README`
)
View Source
var (
	SystemedSRV = `` /* 389-byte string literal not displayed */

)
View Source
var (
	TOML = `` /* 893-byte string literal not displayed */

)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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