-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename some packages and functions (#41)
* refactor: rename `schema` to `config` * refactor: rename `schema.ReadFile` to `config.LoadConfig` * chore: remove unused files * chore: fix linting error * chore: rename `ReservedAS0` to `AS0` * chore: inline `Any` function * chore: remove extra space * refactor: rename `database` to `iprange` and `utils` to `iputils` * chore: update package description
- Loading branch information
Showing
18 changed files
with
218 additions
and
602 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Package config contains the schema and helper functions to work with the | ||
// configuration file. | ||
package config | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/go-playground/validator/v10" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// isCIDRField checks if the value of the given field is a valid CIDR. | ||
func isCIDRField(field validator.FieldLevel) bool { | ||
cidr, ok := field.Field().Interface().(CIDR) | ||
if !ok || cidr.IPNet == nil { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// read reads the configuration from the giver bytes slice. | ||
func read(data []byte) (*Configuration, error) { | ||
var config Configuration | ||
if err := yaml.Unmarshal(data, &config); err != nil { | ||
return nil, err | ||
} | ||
|
||
validate := validator.New() | ||
validate.RegisterValidation("cidr", isCIDRField) // #nosec G104 | ||
|
||
if err := validate.Struct(config); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &config, nil | ||
} | ||
|
||
// LoadConfig reads the configuration from the given file. | ||
func LoadConfig(filename string) (*Configuration, error) { | ||
data, err := os.ReadFile(filename) // #nosec G304 | ||
if err != nil { | ||
return nil, err | ||
} | ||
return read(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package schema | ||
package config | ||
|
||
import "net" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package database | ||
package iprange | ||
|
||
var ( | ||
StrToASN = strToASN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.