mirror of
https://github.com/jixishi/SerialTerminalForWindowsTerminal.git
synced 2026-06-16 00:52:44 +00:00
refactor: extract internal/config and eliminate global config var
Move Config struct to internal/config with exported fields. Replace global var config with package-level cfg pointer. Add OpenLogFile to config package. Add type alias Config = appconfig.Config in main package for backward compatibility. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,42 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
appconfig "github.com/jixishi/SerialTerminalForWindowsTerminal/internal/config"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
portName string
|
||||
baudRate int
|
||||
dataBits int
|
||||
stopBits int
|
||||
parityBit int
|
||||
outputCode string
|
||||
inputCode string
|
||||
endStr string
|
||||
enableLog bool
|
||||
logFilePath string
|
||||
forWard []int
|
||||
frameSize int
|
||||
timesTamp bool
|
||||
timesFmt string
|
||||
address []string
|
||||
enableGUI bool
|
||||
hotkeyMod string
|
||||
}
|
||||
// Config is an alias for appconfig.Config to keep main-package code concise.
|
||||
type Config = appconfig.Config
|
||||
|
||||
var config Config
|
||||
|
||||
func openLogFile() (*os.File, error) {
|
||||
if config.enableLog {
|
||||
path := fmt.Sprintf(config.logFilePath, config.portName, time.Now().Format("2006_01_02T150405"))
|
||||
f, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
var cfg = &Config{}
|
||||
|
||||
Reference in New Issue
Block a user