add opts struct to class logo method
All checks were successful
Build and Publish / check-chart (push) Successful in 14s
Build and Publish / helm-release (push) Successful in 59s
Build and Publish / release (push) Successful in 3m46s

This commit is contained in:
2025-07-08 20:44:24 -04:00
parent d5abda89a1
commit 7e78b271f4
3 changed files with 25 additions and 8 deletions

View File

@ -1,3 +1,5 @@
// Package classgrpc provides demonstrative rpc implementation for class server
// TODO: Move font and text to ClassServiceOpts in New() and use
package classgrpc
import (
@ -11,17 +13,25 @@ import (
type ClassService struct {
class.UnimplementedClassServiceServer
ctx context.Context
ctx context.Context
font class.Font
text string
}
type ClassServiceOpts struct {
Ctx context.Context
Font class.Font
Text string
}
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
req.Font = s.font
}
f := figure.NewFigure("Indiana Tech", getFontString(req.GetFont()), false)
f := figure.NewFigure(s.text, getFontString(req.GetFont()), false)
resp := &class.GetClassLogoResponse{
LogoBytes: []byte(f.String()),
@ -38,8 +48,10 @@ func getFontString(font class.Font) string {
return strings.ToLower(strings.ReplaceAll(font.String(), "FONT_", ""))
}
func New(ctx context.Context) *ClassService {
func New(opts *ClassServiceOpts) *ClassService {
return &ClassService{
ctx: ctx,
ctx: opts.Ctx,
font: opts.Font,
text: opts.Text,
}
}