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,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user