refactor(grpc): restructure task handling and migrate to slog
All checks were successful
Build / build (push) Successful in 5m28s
All checks were successful
Build / build (push) Successful in 5m28s
Refactor the gRPC client and task handling logic to improve modularity, error handling, and observability. - Split `grpc/handler.go` into specialized handler files (login, classroom, exams, grades, schedule) to reduce complexity. - Replace standard `log` with `log/slog` throughout the project for structured logging. - Refactor `grpc/client.go` to use a thread-safe connection management pattern with `sync.RWMutex`. - Remove the legacy `service` package and HTTP server implementation, transitioning the application to a pure gRPC runner mode. - Clean up `config` and `pkg/errors` to remove unused utilities and simplify the API. - Improve error reporting in parsers and HTTP clients by checking response status codes.
This commit is contained in:
@@ -5,51 +5,29 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultLevel = slog.LevelInfo
|
||||
logger *slog.Logger
|
||||
)
|
||||
var currentLevel = slog.LevelInfo
|
||||
|
||||
func init() {
|
||||
opts := &slog.HandlerOptions{
|
||||
Level: defaultLevel,
|
||||
Level: currentLevel,
|
||||
}
|
||||
logger = slog.New(slog.NewJSONHandler(os.Stdout, opts))
|
||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, opts))
|
||||
slog.SetDefault(logger)
|
||||
}
|
||||
|
||||
func SetLevel(level slog.Level) {
|
||||
currentLevel = level
|
||||
opts := &slog.HandlerOptions{
|
||||
Level: level,
|
||||
Level: currentLevel,
|
||||
}
|
||||
logger = slog.New(slog.NewJSONHandler(os.Stdout, opts))
|
||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, opts))
|
||||
slog.SetDefault(logger)
|
||||
}
|
||||
|
||||
func SetTextHandler() {
|
||||
opts := &slog.HandlerOptions{
|
||||
Level: defaultLevel,
|
||||
Level: currentLevel,
|
||||
}
|
||||
logger = slog.New(slog.NewTextHandler(os.Stdout, opts))
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, opts))
|
||||
slog.SetDefault(logger)
|
||||
}
|
||||
|
||||
func Debug(msg string, args ...any) {
|
||||
slog.Debug(msg, args...)
|
||||
}
|
||||
|
||||
func Info(msg string, args ...any) {
|
||||
slog.Info(msg, args...)
|
||||
}
|
||||
|
||||
func Warn(msg string, args ...any) {
|
||||
slog.Warn(msg, args...)
|
||||
}
|
||||
|
||||
func Error(msg string, args ...any) {
|
||||
slog.Error(msg, args...)
|
||||
}
|
||||
|
||||
func With(args ...any) *slog.Logger {
|
||||
return slog.With(args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user