-
Notifications
You must be signed in to change notification settings - Fork 151
Comparison with spf13 viper
Kailash Nadh edited this page May 28, 2021
·
2 revisions
There are several issues with spf13/viper, but the biggest one, after the case-insensitive behaviour is the large number of dependencies that are hardcoded in the core. This bloat is illustrated below with two simple programs, one in koanf and one in viper, that read a JSON file and prints the keys. The viper binary is 313% bigger than the koanf one. A simple encoding/json example is also included to serve as a baseline.
package main
import (
"log"
"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/json"
"github.com/knadh/koanf/providers/file"
)
func main() {
var k = koanf.New(".")
// Load JSON config.
if err := k.Load(file.Provider("mock/mock.json"), json.Parser()); err != nil {
log.Fatalf("error loading config: %v", err)
}
k.Print()
}
package main
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
viper.SetConfigFile("mock/mock.json")
viper.ReadInConfig()
fmt.Println(viper.AllKeys())
}
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
func main() {
b, _ := ioutil.ReadFile("mock/mock.json")
var v map[string]interface{}
json.Unmarshal(b, &v)
fmt.Println(v)
}