Move mastodon URL to a .env var

This commit is contained in:
idanoo 2023-01-29 20:26:02 +13:00
parent ae803d1127
commit b17f929948
Signed by: idanoo
GPG Key ID: 387387CDBC02F132
3 changed files with 31 additions and 10 deletions

View File

@ -1,6 +1,7 @@
MATRIX_WEBHOOK_URL= MATRIX_WEBHOOK_URL="http://127.0.0.1:4785"
MATRIX_WEBHOOK_API_KEY= MATRIX_WEBHOOK_API_KEY=keySetupInMatrixWebhooks
MATRIX_ACCOUNT_CHANNEL= MATRIX_ACCOUNT_CHANNEL="!channelID:matrix.org"
MATRIX_REPORT_CHANNEL= MATRIX_REPORT_CHANNEL="!channelID:matrix.org"
PORT= PORT=8081
IP2LOCATION_FILE= IP2LOCATION_FILE="full path to .BIN file"
MASTODON_INSTANCE="mastodon.test"

View File

@ -6,4 +6,15 @@ Allows you to post signup/report info into a Matrix channel.
# Install # Install
Install golang. Install [matrix-webhook](https://github.com/nim65s/matrix-webhook). Install golang. Install [matrix-webhook](https://github.com/nim65s/matrix-webhook).
Copy .env.example to .env and fill in the blanks Copy .env.example to .env and fill in the blanks
```
MATRIX_WEBHOOK_URL="http://127.0.0.1:4785"
MATRIX_WEBHOOK_API_KEY=keySetupInMatrixWebhooks
MATRIX_ACCOUNT_CHANNEL="!channelID:matrix.org"
MATRIX_REPORT_CHANNEL="!channelID:matrix.org"
PORT=8081
IP2LOCATION_FILE="full path to .BIN file"
MASTODON_INSTANCE="mastodon.test"
```

15
main.go
View File

@ -18,6 +18,7 @@ var MATRIX_ACCOUNT_CHANNEL string
var MATRIX_REPORT_CHANNEL string var MATRIX_REPORT_CHANNEL string
var PORT string var PORT string
var IP2LOCATION_FILE string var IP2LOCATION_FILE string
var MASTODON_INSTANCE string
func init() { func init() {
err := godotenv.Load() err := godotenv.Load()
@ -45,6 +46,11 @@ func init() {
log.Fatal("MATRIX_REPORT_CHANNEL empty or invalid") log.Fatal("MATRIX_REPORT_CHANNEL empty or invalid")
} }
MASTODON_INSTANCE = os.Getenv("MASTODON_INSTANCE")
if MASTODON_INSTANCE == "" {
log.Fatal("MASTODON_INSTANCE is empty or invalid")
}
PORT = os.Getenv("PORT") PORT = os.Getenv("PORT")
if PORT == "" { if PORT == "" {
log.Fatal("PORT empty or invalid") log.Fatal("PORT empty or invalid")
@ -75,7 +81,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
msg := fmt.Sprintf( msg := fmt.Sprintf(
"[New Report](%s): **%s** has reported **%s**: %s", "[New Report](%s): **%s** has reported **%s**: %s",
fmt.Sprintf( fmt.Sprintf(
"https://mastodon.nz/admin/reports/%s", "https://%s/admin/reports/%s",
MASTODON_INSTANCE,
i.Object.ID, i.Object.ID,
), ),
i.Object.Account.Username, i.Object.Account.Username,
@ -101,7 +108,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
msg := fmt.Sprintf( msg := fmt.Sprintf(
"[New Signup](%s) %s: **%s** (%s). %s", "[New Signup](%s) %s: **%s** (%s). %s",
fmt.Sprintf( fmt.Sprintf(
"https://mastodon.nz/admin/accounts/%s", "https://%s/admin/accounts/%s",
MASTODON_INSTANCE,
i.Object.ID, i.Object.ID,
), ),
country, country,
@ -129,7 +137,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
msg := fmt.Sprintf( msg := fmt.Sprintf(
"[Signup Approved](%s): %s", "[Signup Approved](%s): %s",
fmt.Sprintf( fmt.Sprintf(
"https://mastodon.nz/admin/accounts/%s", "https://%s/admin/accounts/%s",
MASTODON_INSTANCE,
i.Object.ID, i.Object.ID,
), ),
i.Object.Username, i.Object.Username,