MCPcopy
hub / github.com/nirui/sshwifty / loadFile

Function loadFile

application/configuration/loader_file.go:124–161  ·  view source on GitHub ↗
(filePath string)

Source from the content-addressed store, hash-verified

122}
123
124func loadFile(filePath string) (string, Configuration, error) {
125 f, fErr := os.Open(filePath)
126
127 if fErr != nil {
128 return fileTypeName, Configuration{}, fErr
129 }
130
131 defer f.Close()
132
133 cfg := fileCfgCommon{}
134
135 jDecoder := json.NewDecoder(f)
136 jDecodeErr := jDecoder.Decode(&cfg)
137
138 if jDecodeErr != nil {
139 return fileTypeName, Configuration{}, jDecodeErr
140 }
141
142 finalCfg, dialer, cfgErr := cfg.build()
143
144 if cfgErr != nil {
145 return fileTypeName, Configuration{}, cfgErr
146 }
147
148 servers := make([]Server, len(finalCfg.Servers))
149
150 for i := range servers {
151 servers[i] = finalCfg.Servers[i].build()
152 }
153
154 return fileTypeName, Configuration{
155 HostName: finalCfg.HostName,
156 SharedKey: finalCfg.SharedKey,
157 Dialer: dialer,
158 DialTimeout: time.Duration(finalCfg.DialTimeout) * time.Second,
159 Servers: servers,
160 }, nil
161}
162
163// File creates a configuration file loader
164func File(customPath string) Loader {

Callers 1

FileFunction · 0.85

Calls 3

buildMethod · 0.95
CloseMethod · 0.65
buildMethod · 0.45

Tested by

no test coverage detected