refactor: introduce service layer and migrate gRPC handlers to use it
All checks were successful
Build / build (push) Successful in 2m17s
All checks were successful
Build / build (push) Successful in 2m17s
Extract business logic from gRPC handlers into a dedicated service package. Add context support throughout for cancellation and timeouts. Move models to their own package, remove hardcoded credentials from config, and simplify parsers to only handle HTML parsing.
This commit is contained in:
@@ -3,17 +3,14 @@ package config
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
Username string
|
||||
Password string
|
||||
Semester string
|
||||
TWFID string
|
||||
BaseURL string
|
||||
Semester string
|
||||
TWFID string
|
||||
Recognizer RecognizerConfig
|
||||
}
|
||||
|
||||
@@ -33,13 +30,11 @@ func Load() *Config {
|
||||
cfgOnce.Do(func() {
|
||||
cfg = &Config{
|
||||
BaseURL: getEnv("JWTS_BASE_URL", "http://jwts.hitwh.edu.cn"),
|
||||
Username: getEnv("JWTS_USERNAME", "2024212193"),
|
||||
Password: getEnv("JWTS_PASSWORD", "wyb12580963"),
|
||||
Semester: getEnv("JWTS_SEMESTER", "2025-20262"),
|
||||
Semester: getEnv("JWTS_SEMESTER", ""),
|
||||
TWFID: getEnv("JWTS_TWFID", ""),
|
||||
Recognizer: RecognizerConfig{
|
||||
APIURL: getEnv("RECOGNIZER_API_URL", "https://api.littlelan.cn/v1/chat/completions"),
|
||||
APIKey: getEnv("RECOGNIZER_API_KEY", "sk-6064466699a996b6f83e1ae8247c1cb4eeb4b72ce23cb001204335a2567d63c1"),
|
||||
APIKey: getEnv("RECOGNIZER_API_KEY", ""),
|
||||
Model: getEnv("RECOGNIZER_MODEL", "qwen3.5-plus"),
|
||||
Timeout: getEnvDuration("RECOGNIZER_TIMEOUT", 120*time.Second),
|
||||
},
|
||||
@@ -67,17 +62,6 @@ func getEnv(key, defaultValue string) string {
|
||||
return val
|
||||
}
|
||||
|
||||
func getEnvInt(key string, defaultValue int) int {
|
||||
val := os.Getenv(key)
|
||||
if val == "" {
|
||||
return defaultValue
|
||||
}
|
||||
if i, err := strconv.Atoi(val); err == nil {
|
||||
return i
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func getEnvDuration(key string, defaultValue time.Duration) time.Duration {
|
||||
val := os.Getenv(key)
|
||||
if val == "" {
|
||||
@@ -91,8 +75,6 @@ func getEnvDuration(key string, defaultValue time.Duration) time.Duration {
|
||||
|
||||
var (
|
||||
BaseURL = Get().BaseURL
|
||||
Username = Get().Username
|
||||
Password = Get().Password
|
||||
Semester = Get().Semester
|
||||
TWFID = Get().TWFID
|
||||
RecognizerAPIURL = Get().Recognizer.APIURL
|
||||
|
||||
Reference in New Issue
Block a user