change to use logging instead of print to stdout

This commit is contained in:
2023-04-03 12:00:01 +10:00
parent f2ac6097d6
commit 5cc67501d3
11 changed files with 88 additions and 87 deletions

View File

@@ -2,6 +2,7 @@ package token
import (
"fmt"
"log"
"os"
"strconv"
"strings"
@@ -15,7 +16,7 @@ func GenerateToken(user_id uint) (string, error) {
token_lifespan, err := strconv.Atoi(os.Getenv("TOKEN_HOUR_LIFESPAN"))
if err != nil {
fmt.Printf("GenerateToken Error getting env value TOKEN_HOUR_LIFESPAN\n")
log.Printf("GenerateToken Error getting env value TOKEN_HOUR_LIFESPAN\n")
return "", err
}

View File

@@ -6,7 +6,6 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"log"
"math/big"
"net"
@@ -25,7 +24,7 @@ func GetFilePath(path string) string {
// check if filename exists
if _, err := os.Stat(path); os.IsNotExist((err)) {
fmt.Printf("File '%s' not found, searching in same directory as binary\n", path)
log.Printf("File '%s' not found, searching in same directory as binary\n", path)
// if not, check that it exists in the same directory as the currently executing binary
ex, err2 := os.Executable()
if err2 != nil {
@@ -76,7 +75,7 @@ func GenerateCerts(tlsCert string, tlsKey string) {
// Check that the directory exists
relativePath := filepath.Dir(tlsCert)
fmt.Printf("GenerateCerts relative path for file creation is '%s'\n", relativePath)
log.Printf("GenerateCerts relative path for file creation is '%s'\n", relativePath)
_, err = os.Stat(relativePath)
if os.IsNotExist(err) {
log.Printf("Certificate path does not exist, creating %s before generating certificate\n", relativePath)
@@ -126,13 +125,13 @@ func GenerateCerts(tlsCert string, tlsKey string) {
ifaces, err := net.Interfaces()
if err != nil {
fmt.Printf("Error enumerating interfaces: %v\n", err)
log.Printf("Error enumerating interfaces: %v\n", err)
}
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
fmt.Printf("Oops: %v\n", err)
log.Printf("Oops: %v\n", err)
}
for _, address := range addrs {