code tidy-up

This commit is contained in:
ari melody 2026-07-24 11:02:32 +01:00
parent a24fbfc96e
commit 2190cac343
Signed by: ari
GPG key ID: CF99829C92678188
5 changed files with 363 additions and 338 deletions

View file

@ -3,6 +3,7 @@ package learning
import (
"context"
"embed"
"fmt"
"io"
"log"
"net/http"
@ -36,7 +37,7 @@ type (
}
)
func New(ctx context.Context, cfg ServiceConfig) *Service {
func New(ctx context.Context, cfg ServiceConfig) (*Service, error) {
titleText := []byte{}
titleUpdated := make(chan string)
@ -45,10 +46,10 @@ func New(ctx context.Context, cfg ServiceConfig) *Service {
os.WriteFile(cfg.TitleFilePath, []byte("Untitled"), 0644)
titleText = []byte("Untitled")
} else if err != nil {
log.Fatalf("Failed to stat title file: %v", err)
return nil, fmt.Errorf("stat %s: %v", cfg.TitleFilePath, err)
} else {
titleText, err = os.ReadFile(cfg.TitleFilePath)
if err != nil { log.Fatalf("Failed to read title file: %v", err) }
if err != nil { return nil, fmt.Errorf("read %s: %v", cfg.TitleFilePath, err) }
}
srv := &Service{
@ -60,7 +61,7 @@ func New(ctx context.Context, cfg ServiceConfig) *Service {
titleUpdatedBroadcast: broadcast.NewBroadcastChannel(ctx, titleUpdated),
}
return srv
return srv, nil
}
func (srv *Service) BindRoutes(group *gin.RouterGroup) {