go fmt / badges

This commit is contained in:
vx3r 2020-01-30 16:17:29 +09:00
parent 9b6d610a9c
commit a1828bfcd8
5 changed files with 19 additions and 19 deletions

View File

@ -2,7 +2,7 @@ package model

import "time"

// client structure
// Client structure
type Client struct {
Id string `json:"id"`
Name string `json:"name"`

View File

@ -2,7 +2,7 @@ package model

import "time"

// server structure
// Server structure
type Server struct {
Name string `json:"name"`
Created time.Time `json:"created"`

View File

@ -17,7 +17,7 @@ import (
)

/*
* Create client with all necessary data
* CreateClient client with all necessary data
*/
func CreateClient(client *model.Client) (*model.Client, error) {
u := uuid.NewV4()
@ -86,7 +86,7 @@ func CreateClient(client *model.Client) (*model.Client, error) {
}

/*
* Read client by id
* ReadClient client by id
*/
func ReadClient(id string) (*model.Client, error) {
v, err := deserialize(id)
@ -99,7 +99,7 @@ func ReadClient(id string) (*model.Client, error) {
}

/*
* Get client config ion wg format
* ReadClientConfig in wg format
*/
func ReadClientConfig(id string) ([]byte, error) {
client, err := ReadClient(id)
@ -121,7 +121,7 @@ func ReadClientConfig(id string) ([]byte, error) {
}

/*
* Update client preserve keys
* UpdateClient preserve keys
*/
func UpdateClient(Id string, client *model.Client) (*model.Client, error) {
v, err := deserialize(Id)
@ -154,7 +154,7 @@ func UpdateClient(Id string, client *model.Client) (*model.Client, error) {
}

/*
* Delete client from disk
* DeleteClient from disk
*/
func DeleteClient(id string) error {
path := filepath.Join(os.Getenv("WG_CONF_DIR"), id)
@ -168,7 +168,7 @@ func DeleteClient(id string) error {
}

/*
* Read all clients
* ReadClients all clients
*/
func ReadClients() ([]*model.Client, error) {
clients := make([]*model.Client, 0)
@ -202,7 +202,7 @@ func ReadClients() ([]*model.Client, error) {
}

/*
* Return server object, create default one
* ReadServer object, create default one
*/
func ReadServer() (*model.Server, error) {
if !util.FileExists(filepath.Join(os.Getenv("WG_CONF_DIR"), "server.json")) {
@ -245,7 +245,7 @@ func ReadServer() (*model.Server, error) {
}

/*
* Update server, keep private values from existing one
* UpdateServer keep private values from existing one
*/
func UpdateServer(server *model.Server) (*model.Server, error) {
current, err := deserialize("server.json")

View File

@ -40,7 +40,7 @@ AllowedIPs = {{.Address}}
{{end}}`
)

// dump client wg config with go template
// DumpClient dump client wg config with go template
func DumpClient(client *model.Client, server *model.Server) (bytes.Buffer, error) {
var tplBuff bytes.Buffer

@ -58,7 +58,7 @@ func DumpClient(client *model.Client, server *model.Server) (bytes.Buffer, error
})
}

// dump server wg config with go template
// DumpServerWg dump server wg config with go template
func DumpServerWg(clients []*model.Client, server *model.Server) (bytes.Buffer, error) {
var tplBuff bytes.Buffer


View File

@ -8,7 +8,7 @@ import (
"strings"
)

// read file content
// ReadFile file content
func ReadFile(path string) (bytes []byte, err error) {
bytes, err = ioutil.ReadFile(path)
if err != nil {
@ -18,7 +18,7 @@ func ReadFile(path string) (bytes []byte, err error) {
return bytes, nil
}

// write content to file
// WriteFile content to file
func WriteFile(path string, bytes []byte) (err error) {
err = ioutil.WriteFile(path, bytes, 0644)
if err != nil {
@ -28,7 +28,7 @@ func WriteFile(path string, bytes []byte) (err error) {
return nil
}

// check if file exists
// FileExists check if file exists
func FileExists(name string) bool {
info, err := os.Stat(name)
if os.IsNotExist(err) {
@ -37,7 +37,7 @@ func FileExists(name string) bool {
return !info.IsDir()
}

// check if directory exists
// DirectoryExists check if directory exists
func DirectoryExists(name string) bool {
info, err := os.Stat(name)
if os.IsNotExist(err) {
@ -46,7 +46,7 @@ func DirectoryExists(name string) bool {
return info.IsDir()
}

// search for an available in cidr against a list of reserved ips
// GetAvailableIp search for an available in cidr against a list of reserved ips
func GetAvailableIp(cidr string, reserved []string) (string, error) {
addresses, err := GetAllAddressesFromCidr(cidr)
if err != nil {
@ -69,7 +69,7 @@ func GetAvailableIp(cidr string, reserved []string) (string, error) {
return "", errors.New("no more available address from cidr")
}

// get all ip addresses from cidr
// GetAllAddressesFromCidr get all ip addresses from cidr
func GetAllAddressesFromCidr(cidr string) ([]string, error) {
ip, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
@ -94,7 +94,7 @@ func inc(ip net.IP) {
}
}

// check if given ip is IPv6
// IsIPv6 check if given ip is IPv6
func IsIPv6(address string) bool {
return strings.Count(address, ":") >= 2
}