add some class foo

This commit is contained in:
Adora Laura Kalb 2023-03-12 21:27:02 +01:00
parent 0fbae78fcf
commit 8475bad2d7
5 changed files with 69 additions and 30 deletions

3
.gitignore vendored
View file

@ -22,3 +22,6 @@ go.work
# build output # build output
output/ output/
# vs code stuff
.vscode/

View file

@ -1,10 +0,0 @@
/*
Copyright © 2023 Laura Kalb <dev@lauka.net>
*/
package classes
type Subnet struct {
subnet string
name string
}

View file

@ -55,27 +55,36 @@ func initConfig() {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
var ipamdir string = homedir + "/.ipam/"
// Search config in home directory with name ".cobra" (without extension). // Search config in home directory with name ".cobra" (without extension).
viper.AddConfigPath(homedir + "/.ipam/") viper.AddConfigPath(ipamdir)
viper.SetConfigName("ipam.yml") viper.SetConfigName("ipam")
viper.SetConfigType("yaml")
viper.SetDefault("EnablePowerDNS", false) viper.SetDefault("EnablePowerDNS", false)
viper.SetDefault("DataPath", homedir+"/.ipam/data/") viper.SetDefault("DataPath", ipamdir+"/data/")
println(homedir + "/.ipam/")
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
//if errfolder := os.MkdirAll(homedir+"/.ipam/", 0664); err != nil { _, patherr := os.Stat(ipamdir)
// println("[ERROR] Can't create config dir!", errfolder) if patherr != nil {
// os.Exit(1) mkerr := os.MkdirAll(ipamdir, 0755)
//} if mkerr != nil {
println("[ERROR] Can't create ipam config directory!", mkerr)
//if errconfig := viper.WriteConfig(); err != nil { }
// println("[ERROR] Can't create config file!", errconfig) }
// os.Exit(1)
//}
// I have no idea what's happening here...
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
writeerr := viper.SafeWriteConfig()
if writeerr != nil {
println("[ERROR] Can't write config file!", writeerr)
}
} else {
println("[ERROR] Can't read config file!", err) println("[ERROR] Can't read config file!", err)
} }
}
fmt.Println(viper.AllKeys())
} }

42
cmd/storage.go Normal file
View file

@ -0,0 +1,42 @@
/*
Copyright © 2023 Laura Kalb <dev@lauka.net>
*/
package cmd
import (
"net"
)
type Subnet struct {
Subnet net.IPNet
Name string
Vlan string
Addresses []Address
}
type Address struct {
IP string
FQDN string
}
// GetSubnet tries to load the most fitting IP subnet file on disk.
// It takes an IP object and tries to get the best subnet (meaning
// the subnet with the smallest subnet size).
//
// Returns the best subnet as Subnet object and true if a suitable
// subnet was found, otherwise an empty Subnet object and false.
func GetSubnet(ip net.IP) (Subnet, bool) {
return Subnet{}, false
}
// WriteSubnet takes a given Subnet object and tries to write it to
// file.
//
// Returns nil on success or the error that happened.
func WriteSubnet(subnet Subnet) error {
//if subnet.Subnet
return nil
}

View file

@ -1,5 +0,0 @@
/*
Copyright © 2023 Laura Kalb <dev@lauka.net>
*/
package storage