-
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.
Also add app config and move things around a bit
- Loading branch information
Showing
5 changed files
with
150 additions
and
47 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package meters | ||
package utils | ||
|
||
import "time" | ||
|
||
|
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,8 @@ | ||
package utils | ||
|
||
type Config struct { | ||
Debug bool | ||
JsonOutput bool | ||
} | ||
|
||
var AppConfig = &Config{} |
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,48 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
) | ||
|
||
func PrintJSON(format string, a ...any) { | ||
if AppConfig.JsonOutput { | ||
fmt.Printf(format, a...) | ||
} | ||
} | ||
|
||
func Debugln(a ...any) { | ||
if AppConfig.Debug { | ||
fmt.Println(a...) | ||
} | ||
} | ||
|
||
func Debugf(format string, a ...any) { | ||
if AppConfig.Debug { | ||
fmt.Printf(format, a...) | ||
} | ||
} | ||
|
||
func Println(a ...any) { | ||
if !AppConfig.JsonOutput { | ||
fmt.Println(a...) | ||
} | ||
} | ||
|
||
func Fprintf(w io.Writer, format string, a ...any) { | ||
if !AppConfig.JsonOutput { | ||
fmt.Fprintf(w, format, a...) | ||
} | ||
} | ||
|
||
func Printf(format string, a ...any) { | ||
if !AppConfig.JsonOutput { | ||
fmt.Printf(format, a...) | ||
} | ||
} | ||
|
||
func Print(a ...any) { | ||
if !AppConfig.JsonOutput { | ||
fmt.Print(a...) | ||
} | ||
} |