generated from rmcguire/go-server-with-otel
implement class logo
This commit is contained in:
45
pkg/classgrpc/class.go
Normal file
45
pkg/classgrpc/class.go
Normal file
@ -0,0 +1,45 @@
|
||||
package classgrpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
figure "github.com/common-nighthawk/go-figure"
|
||||
|
||||
class "gitea.libretechconsulting.com/rmcguire/class-server/api/class/v1alpha1"
|
||||
)
|
||||
|
||||
type ClassService struct {
|
||||
class.UnimplementedClassServiceServer
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
var DefaultFont = class.Font_FONT_BARBWIRE
|
||||
|
||||
func (s *ClassService) GetClassLogo(ctx context.Context, req *class.GetClassLogoRequest) (*class.GetClassLogoResponse, error) {
|
||||
if req.GetFont() == class.Font_FONT_UNSPECIFIED {
|
||||
req.Font = DefaultFont
|
||||
}
|
||||
|
||||
f := figure.NewFigure("Indiana Tech", getFontString(req.GetFont()), false)
|
||||
|
||||
resp := &class.GetClassLogoResponse{
|
||||
LogoBytes: []byte(f.String()),
|
||||
}
|
||||
|
||||
if req.GetIncludeString() {
|
||||
resp.LogoString = f.String()
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func getFontString(font class.Font) string {
|
||||
return strings.ToLower(strings.ReplaceAll(font.String(), "FONT_", ""))
|
||||
}
|
||||
|
||||
func New(ctx context.Context) *ClassService {
|
||||
return &ClassService{
|
||||
ctx: ctx,
|
||||
}
|
||||
}
|
30
pkg/classgrpc/server.go
Normal file
30
pkg/classgrpc/server.go
Normal file
@ -0,0 +1,30 @@
|
||||
package classgrpc
|
||||
|
||||
import (
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
class "gitea.libretechconsulting.com/rmcguire/class-server/api/class/v1alpha1"
|
||||
)
|
||||
|
||||
func (s *ClassService) GetDialOpts() []grpc.DialOption {
|
||||
return []grpc.DialOption{
|
||||
// NOTE: Necessary for grpc-gateway to connect to grpc server
|
||||
// Update if grpc service has credentials, tls, etc..
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ClassService) GetServices() []*opts.GRPCService {
|
||||
return []*opts.GRPCService{
|
||||
{
|
||||
Name: "Class App",
|
||||
Type: &class.ClassService_ServiceDesc,
|
||||
Service: s,
|
||||
GwRegistrationFuncs: []opts.GwRegistrationFunc{
|
||||
class.RegisterClassServiceHandler,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user