conventional naming

This commit is contained in:
Baipyrus 2024-04-12 13:30:00 +02:00
parent 85b96a5ea3
commit 775ea88bd3

28
main.go
View File

@ -45,7 +45,7 @@ type Rectangle struct {
Endpoint Endpoint `json:"endpoint"`
}
func GetEnvFallback(key string, fallback ...string) (string, error) {
func getEnvFallback(key string, fallback ...string) (string, error) {
// Check for function fallback signature
length := len(fallback)
if length > 1 {
@ -70,7 +70,7 @@ func GetEnvFallback(key string, fallback ...string) (string, error) {
return "", errors.New("Could not get environment variable: " + key)
}
func ConvertFallback(input string, fallback ...int) (int, error) {
func convertFallback(input string, fallback ...int) (int, error) {
// Check for function fallback signature
length := len(fallback)
if length > 1 {
@ -95,18 +95,18 @@ func ConvertFallback(input string, fallback ...int) (int, error) {
return 0, err
}
func LoadMatrixData() (string, int, int) {
func loadMatrixData() (string, int, int) {
// Remote server info
API_SERVER_IP, _ := GetEnvFallback("API_SERVER_IP", "localhost")
API_SERVER_PORT, _ := GetEnvFallback("API_SERVER_PORT", "8080")
API_SERVER_IP, _ := getEnvFallback("API_SERVER_IP", "localhost")
API_SERVER_PORT, _ := getEnvFallback("API_SERVER_PORT", "8080")
// LED panel info
PUBLIC_LED_WIDTH, _ := ConvertFallback(os.Getenv("PUBLIC_LED_WIDTH"), 64)
PUBLIC_LED_HEIGHT, _ := ConvertFallback(os.Getenv("PUBLIC_LED_HEIGHT"), 64)
PUBLIC_LED_WIDTH, _ := convertFallback(os.Getenv("PUBLIC_LED_WIDTH"), 64)
PUBLIC_LED_HEIGHT, _ := convertFallback(os.Getenv("PUBLIC_LED_HEIGHT"), 64)
// Matrix arrangement info
PUBLIC_LED_CHAIN, _ := ConvertFallback(os.Getenv("PUBLIC_LED_CHAIN"), 1)
PUBLIC_LED_PARALLEL, _ := ConvertFallback(os.Getenv("PUBLIC_LED_PARALLEL"), 1)
PUBLIC_LED_CHAIN, _ := convertFallback(os.Getenv("PUBLIC_LED_CHAIN"), 1)
PUBLIC_LED_PARALLEL, _ := convertFallback(os.Getenv("PUBLIC_LED_PARALLEL"), 1)
// Prepare remote server url
url := fmt.Sprintf("http://%s:%s", API_SERVER_IP, API_SERVER_PORT)
@ -118,7 +118,7 @@ func LoadMatrixData() (string, int, int) {
return url, width, height
}
func CreateInsructions(marshal []byte) (*bytes.Buffer, string) {
func createInsructions(marshal []byte) (*bytes.Buffer, string) {
// Create a new form data object
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
@ -137,7 +137,7 @@ func CreateInsructions(marshal []byte) (*bytes.Buffer, string) {
return body, writer.FormDataContentType()
}
func SendRequest(client *resty.Client, url string, ins []interface{}) {
func sendRequest(client *resty.Client, url string, ins []interface{}) {
// Manually marshal instructions
marshal, err := json.Marshal(ins)
if err != nil {
@ -149,7 +149,7 @@ func SendRequest(client *resty.Client, url string, ins []interface{}) {
log.Printf("Request: %s\n", string(marshal))
// Create instructions form data
req, content := CreateInsructions(marshal)
req, content := createInsructions(marshal)
if req == nil {
return
}
@ -189,7 +189,7 @@ func main() {
}
// Load env server data
url, width, height := LoadMatrixData()
url, width, height := loadMatrixData()
log.Printf("At '%s': %d x %d\n", url, width, height)
// Initialize resty client
@ -201,5 +201,5 @@ func main() {
upd := Update{Endpoint: UPDATE}
// Send request to remote server
SendRequest(client, url, []interface{}{col, rct, upd})
sendRequest(client, url, []interface{}{col, rct, upd})
}