-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #32: Implement flags and config
- Loading branch information
Showing
10 changed files
with
174 additions
and
51 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@echo off | ||
SETLOCAL | ||
|
||
PUSHD %~dp0 | ||
|
||
set GO111MODULE=on | ||
|
||
PUSHD src | ||
|
||
SET SRCFILES=mumble-www.go githubcache.go snapshotcache.go config.go downloads.go programflags.go | ||
|
||
go build -o ..\mumble-www.exe %SRCFILES% | ||
IF ERRORLEVEL 1 (EXIT /B 1) | ||
|
||
SET GOOS=linux | ||
go build -o ..\mumble-www %SRCFILES% | ||
IF ERRORLEVEL 1 (EXIT /B 1) | ||
|
||
POPD | ||
|
||
POPD |
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
type Config struct { | ||
Host string `yaml:host` | ||
Port int `yaml:port` | ||
PublicPath string `yaml:publicpath` | ||
GitHubCacheTimeMins int `yaml:githubcachetimemins` | ||
} | ||
|
||
func NewConfig() *Config { | ||
return &Config{} | ||
} | ||
|
||
func ReadConfig(path string) (c *Config, err error) { | ||
c = NewConfig() | ||
err = ReadConfigInto(path, c) | ||
return | ||
} | ||
|
||
func ReadConfigInto(path string, c *Config) (err error) { | ||
yamlFile, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return | ||
} | ||
err = yaml.Unmarshal(yamlFile, c) | ||
return | ||
} |
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func setupDownloadsStable(mux *http.ServeMux) { | ||
stable := map[string]string{ | ||
"windows-32": "https://github.com/mumble-voip/mumble/releases/download/1.2.19/mumble-1.2.19.msi", | ||
"osx": "https://github.com/mumble-voip/mumble/releases/download/1.2.19/Mumble-1.2.19.dmg", | ||
"osx-universal": "https://github.com/mumble-voip/mumble/releases/download/1.2.10/Mumble-Universal-1.2.10.dmg", | ||
"ios": "http://itunes.apple.com/us/app/mumble/id443472808?ls=1&mt=8", | ||
"ubuntu": "https://launchpad.net/~mumble/+archive/release", | ||
"linux-static-server": "https://github.com/mumble-voip/mumble/releases/download/1.2.19/murmur-static_x86-1.2.19.tar.bz2", | ||
"osx-static-server": "https://github.com/mumble-voip/mumble/releases/download/1.2.19/Murmur-OSX-Static-1.2.19.tar.bz2", | ||
} | ||
|
||
for source, target := range stable { | ||
mux.Handle("/downloads/"+source, http.RedirectHandler(target, http.StatusTemporaryRedirect)) | ||
} | ||
} | ||
|
||
func setupDownloadsSnapshot(mux *http.ServeMux) { | ||
snapshotCache := NewSnapshotCache(time.Hour) | ||
for source := range snapshotRegexps { | ||
mux.Handle("/downloads/"+source+"/snapshot", snapshotCache.Handle(source)) | ||
} | ||
mux.Handle( | ||
"/downloads/ubuntu/snapshot", | ||
http.RedirectHandler("https://launchpad.net/~mumble/+archive/snapshot", http.StatusTemporaryRedirect), | ||
) | ||
} |
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,7 +1,8 @@ | ||
module "https: //github.com/mumble-voip/mumble-www" | ||
module github.com/mumble-voip/mumble-www | ||
|
||
require ( | ||
github.com/PuerkitoBio/goquery v1.5.0 | ||
github.com/google/go-github v17.0.0+incompatible | ||
github.com/google/go-querystring v1.0.0 // indirect | ||
gopkg.in/yaml.v2 v2.2.2 | ||
) |
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
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,4 @@ | ||
host: 127.0.0.1 | ||
port: 8081 | ||
publicpath: public | ||
githubcachetimemins: 10 |
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,60 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
) | ||
|
||
type Flags struct { | ||
ConfigPath string | ||
Host string | ||
Port int | ||
PublicPath string | ||
GitHubCacheTimeMins int | ||
} | ||
|
||
func NewFlags() *Flags { | ||
return &Flags{} | ||
} | ||
|
||
func ParseFlags() (f *Flags) { | ||
f = NewFlags() | ||
flag.StringVar(&f.ConfigPath, "config", "", "path to yaml config file") | ||
flag.StringVar(&f.Host, "host", "", "bind host address") | ||
flag.IntVar(&f.Port, "port", 0, "bind port number") | ||
flag.StringVar(&f.PublicPath, "publicpath", "", "path to public web files folder") | ||
flag.IntVar(&f.GitHubCacheTimeMins, "githubcachetimemins", 0, "Cache time in minutes to cache GitHub content") | ||
flag.Parse() | ||
return | ||
} | ||
|
||
func ParseInit() (config *Config) { | ||
flags := ParseFlags() | ||
|
||
if flags.ConfigPath == "" && (flags.Host == "" || flags.Port == 0 || flags.PublicPath == "" || flags.GitHubCacheTimeMins == 0) { | ||
flag.Usage() | ||
log.Fatalln("Missing parameter config or complete configuration parameters") | ||
} | ||
|
||
config = NewConfig() | ||
if flags.ConfigPath != "" { | ||
err := ReadConfigInto(flags.ConfigPath, config) | ||
if err != nil { | ||
log.Fatalf("Failed to read config file at %s. Error: %s", flags.ConfigPath, err) | ||
} | ||
} | ||
|
||
if flags.Host != "" { | ||
config.Host = flags.Host | ||
} | ||
if flags.Port != 0 { | ||
config.Port = flags.Port | ||
} | ||
if flags.PublicPath != "" { | ||
config.PublicPath = flags.PublicPath | ||
} | ||
if flags.GitHubCacheTimeMins != 0 { | ||
config.GitHubCacheTimeMins = flags.GitHubCacheTimeMins | ||
} | ||
return | ||
} |