Skip to content

Commit 38658fa

Browse files
committed
add name
1 parent 6ae6d3a commit 38658fa

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

internal/utils/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
// config is the configuration struct
1212
type Config struct {
13+
// Name of the server running the app
14+
Name string
1315
LogFilePath string
1416
DBFilePath string
1517
InstanceID string
@@ -23,6 +25,7 @@ func GetConf(path string) *Config {
2325
viper.AddConfigPath(path)
2426
viper.SetConfigName("config")
2527
viper.SetConfigType("yaml")
28+
viper.SetDefault("Name", "")
2629
viper.SetDefault("LogFilePath", "./logs/")
2730
viper.SetDefault("DBFilePath", "./db")
2831
viper.SetDefault("InstanceID", "")

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ func main() {
2424
if err != nil {
2525
app.Logger.Error(err)
2626
}
27+
28+
if app.Config.Name == "" {
29+
app.Config.Name = hostname
30+
}
2731
// app.Notifier = pusher.Pusher{InstanceID: app.Config.InstanceID, SecretKey: app.Config.SecretKey, Data: &app.Data}
2832
app.Notifier = discord_notifier.NewDiscordNotifier(app.Config.DiscordWebhookURL)
2933
// * re-enable when back online
30-
id, err := app.Notifier.SendMessage([]string{"hello"}, "NotifAPI", "NotifAPI is starting up on "+hostname, "main.go")
34+
id, err := app.Notifier.SendMessage([]string{"hello"}, "NotifAPI", "NotifAPI is starting up on "+app.Config.Name, "main.go")
3135
if err != nil {
3236
app.Logger.ErrorWithField("Error sending message", "interest", "hello")
3337
}

notifapi.http

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
GET http://127.0.0.1:8080/api/ping
2-
3-
HTTP/1.1 200 - OK
4-
content-type: application/json
5-
date: Tue, 25 Feb 2025 17:24:33 GMT
6-
content-length: 8
7-
connection: close
1+
@host = http://127.0.0.1:8080
2+
###
3+
GET /api/ping
84
###
9-
POST http://localhost:8080/api/notify
5+
POST /api/notify
106

117
{
128
"interests": ["hello"],

0 commit comments

Comments
 (0)