Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Allow port number to be configured via param, config file #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/github.com/t3chguy/matrix-static/matrix-static.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"bytes"
"encoding/json"
"flag"
log "github.com/Sirupsen/logrus"
"github.com/disintegration/letteravatar"
Expand All @@ -30,6 +31,7 @@ import (
"github.com/t3chguy/matrix-static/templates"
"github.com/t3chguy/matrix-static/utils"
"image/png"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand All @@ -47,6 +49,7 @@ const RoomMembersPageSize = 20
type configVars struct {
ConfigFile string
NumWorkers int
PortNumber int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems entirely unused


PublicServePrefix string
EnablePrometheusMetrics bool
Expand All @@ -60,6 +63,7 @@ func main() {

flag.StringVar(&config.ConfigFile, "config-file", "./config.json", "The path to the desired config file.")
flag.IntVar(&config.NumWorkers, "num-workers", 32, "Number of Worker goroutines to start.")
flag.IntVar(&config.PortNumber, "port", 8000, "TCP port number on which to listen for HTTP connections.")

flag.StringVar(&config.PublicServePrefix, "public-serve-prefix", "/", "Prefix for publicly accessible routes.")
flag.BoolVar(&config.EnablePrometheusMetrics, "enable-prometheus-metrics", false, "Whether or not to enable the /metrics endpoint.")
Expand Down Expand Up @@ -341,9 +345,30 @@ func main() {
})
}

// The struct representing the json config file format.
type Config struct {
AccessToken string `json:"access_token"`
DeviceID string `json:"device_id"`
HomeServer string `json:"home_server"`
RefreshToken string `json:"refresh_token"`
UserID string `json:"user_id"`
MediaBaseUrl string `json:"media_base_url"`
PortNumber int `json:"port"`
}

var innerConfig Config

port := os.Getenv("PORT")

if port == "" {
port = "8000"
file, err := ioutil.ReadFile(config.ConfigFile)
if err != nil {
// return nil, err
}

json.Unmarshal(file, &innerConfig)

port = strconv.Itoa(innerConfig.PortNumber)
}

go startForwardPaginator(workers)
Expand Down
1 change: 1 addition & 0 deletions src/github.com/t3chguy/matrix-static/mxclient/mxclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type Config struct {
RefreshToken string `json:"refresh_token"`
UserID string `json:"user_id"`
MediaBaseUrl string `json:"media_base_url"`
PortNumber int `json:"port"`
}

// NewClient returns a Client configured by the config file found at configPath or an error if encountered.
Expand Down