保留可配置入口,未启用

This commit is contained in:
nuknal
2024-05-30 11:46:50 +08:00
parent 07ee4d88d4
commit e4d6b35702
11 changed files with 159 additions and 28 deletions

View File

@@ -1,8 +1,35 @@
package config
type CoRegistrationConfig struct {
CRBlockNW int `yaml:"cr_block_nw" mapstructure:"cr_block_nw"`
CRBlockNH int `yaml:"cr_block_nh" mapstructure:"cr_block_nh"`
CRResampleMethod string `yaml:"cr_resample_method" mapstructure:"cr_resample_method"`
FUSBandOrder string `yaml:"fu_band_order" mapstructure:"fu_band_order"`
type Config struct {
CRConfig CoRegistrationConfig `yaml:"cr_config" mapstructure:"cr_config"`
}
type CoRegistrationConfig struct {
MssBands int `yaml:"mss_bands" mapstructure:"mss_bands"`
PixelBytes int `yaml:"pixel_bytes" mapstructure:"pixel_bytes"`
MssWidth int `yaml:"mss_width" mapstructure:"mss_width"`
PanWidth int `yaml:"pan_width" mapstructure:"pan_width"`
CRBlockNW int `yaml:"cr_block_nw" mapstructure:"cr_block_nw"`
CRBlockNH int `yaml:"cr_block_nh" mapstructure:"cr_block_nh"`
OverlappedBlockLines int `yaml:"overlapped_block_lines" mapstructure:"overlapped_block_lines"`
CRResampleMethod string `yaml:"cr_resample_method" mapstructure:"cr_resample_method"`
FUSBandOrder string `yaml:"fu_band_order" mapstructure:"fu_band_order"`
}
var GCONFIG Config
func init() {
GCONFIG = Config{
CRConfig: CoRegistrationConfig{
MssBands: 4,
PixelBytes: 2,
PanWidth: 9344,
MssWidth: 2336,
OverlappedBlockLines: 3000,
CRBlockNW: 8,
CRBlockNH: 4,
CRResampleMethod: "down_sample_pan",
FUSBandOrder: "RGB",
},
}
}

44
pkg/config/viper.go Normal file
View File

@@ -0,0 +1,44 @@
package config
import (
"fmt"
"strings"
"log"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
)
var viperInst *viper.Viper
func InitViper(cfg string) *viper.Viper {
v := viper.New()
v.AutomaticEnv()
v.SetEnvPrefix("sjy01_ip")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.SetConfigFile(cfg)
v.SetConfigType("yaml")
err := v.ReadInConfig()
if err != nil {
log.Println(fmt.Errorf("fatal error config file: %s", err.Error()))
return nil
}
v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) {
if err := v.Unmarshal(&GCONFIG); err != nil {
fmt.Println(err)
}
log.Println("config file changed", e.Name, err)
})
if err := v.Unmarshal(&GCONFIG); err != nil {
fmt.Println(err)
}
return v
}