generated from rmcguire/go-server-with-otel
add opts struct to class logo method
This commit is contained in:
@ -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,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user