generated from rmcguire/go-server-with-otel
46 lines
968 B
Go
46 lines
968 B
Go
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,
|
|
}
|
|
}
|