grim/peacock

13d711f5f347
Parents 2e4a837c83bc
Children 3e444a686381
Get the server running with the basic static stuff
--- a/config/config.go Sat May 26 17:38:03 2018 -0500
+++ b/config/config.go Sat May 26 17:38:15 2018 -0500
@@ -5,8 +5,10 @@
)
type Config struct {
- Hostname string `envconfig:"HOSTNAME"`
- Port int32 `envconfig:"PORT"`
+ ListenAddr string `envconfig:"LISTEN_ADDR" default:"0.0.0.0:9999"`
+ Hostname string `envconfig:"HOSTNAME"`
+ Port int32 `envconfig:"PORT"`
+ StaticFilesPath string `envconfig:"STATIC_FILES_PATH" default:"static"`
}
var (
--- a/main.go Sat May 26 17:38:03 2018 -0500
+++ b/main.go Sat May 26 17:38:15 2018 -0500
@@ -3,16 +3,52 @@
import (
"fmt"
"os"
+ "os/signal"
"runtime/debug"
+ "syscall"
+
+ "github.com/aphistic/gomol"
"bitbucket.org/rw_grim/peacock/logging"
+ "bitbucket.org/rw_grim/peacock/server"
)
func gomain() int {
- logging.Start()
+ err := logging.Start()
+ if err != nil {
+ fmt.Printf("error: %s\n", err)
+ return 1
+ }
defer logging.Stop()
- return 0
+ // setup a signal channel
+ signalChan := make(chan os.Signal, 1)
+ signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
+
+ // setup the error channel
+ errChan := make(chan error, 10)
+
+ // run the api
+ go func() {
+ srv := server.New(errChan)
+ defer srv.Stop()
+ srv.Start()
+ }()
+
+ for {
+ select {
+ case err := <-errChan:
+ if err != nil {
+ gomol.Fatalf("error: %s", err)
+
+ return 1
+ }
+ case s := <-signalChan:
+ gomol.Warnf("Captured %v. Exiting...", s)
+
+ return 0
+ }
+ }
}
func main() {
--- a/server/server.go Sat May 26 17:38:03 2018 -0500
+++ b/server/server.go Sat May 26 17:38:15 2018 -0500
@@ -3,6 +3,7 @@
import (
"net/http"
+ "github.com/aphistic/gomol"
"github.com/aphistic/negroni-gomol"
"github.com/pilu/xrequestid"
"github.com/urfave/negroni"
@@ -32,8 +33,13 @@
return n
}
-func setupRoutes() *http.Handler {
+func setupRoutes(cfg config.Config) http.Handler {
+ router := http.NewServeMux()
+ static := http.FileServer(http.Dir(cfg.StaticFilesPath))
+ router.Handle("/", static)
+
+ return router
}
func New(errChan chan error) *Server {
@@ -52,8 +58,15 @@
}
func (s *Server) Start() {
+ cfg := config.Get()
+ gomol.Infof("Webserver listening on %s", cfg.ListenAddr)
+ s.server.ListenAndServe()
}
func (s *Server) Stop() {
+ if s.server != nil {
+ s.server.Close()
+ s.server = nil
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/css/app.css Sat May 26 17:38:15 2018 -0500
@@ -0,0 +1,87 @@
+html {
+ margin: 0;
+ padding: 0;
+}
+
+body {
+ background-color: #bcd765 !important;
+ font-family: 'Source Code Pro', monospace !important;
+ font-weight: bold !important;
+ font-style: normal !important;
+
+ margin: 0;
+ padding: 0;
+}
+
+#app {
+ height: 100vh;
+ width: 100%;
+
+ display: grid;
+ grid-template-columns: repeat(2, 1fr);
+ grid-template-rows: repeat(2, 1fr);
+}
+
+div.title-block {
+ grid-row: 1;
+ grid-column: 1;
+}
+
+div.name {
+ font-size: xx-large;
+}
+
+div.titles {
+ font-size: x-large;
+}
+
+div.vcard-container {
+ grid-row: 2;
+ grid-column: 1;
+
+ display: grid;
+ grid-template-rows: repeat(2, 1fr);
+}
+
+div.vcard-wrapper {
+ grid-row: 2;
+}
+
+div.vcard {
+ display: inline-block;
+ font-size: large;
+ background-color: #272822;
+}
+
+div.vcard i {
+ width: 1em;
+}
+
+div.vcard a {
+ text-decoration: none;
+ color: #e6db74;
+}
+
+div.reaper {
+ grid-column: 2;
+ grid-row: 1 / 3;
+ background-image: url('/img/grim-transparentish.png');
+ background-size: 100vh;
+ background-repeat: no-repeat;
+}
+
+.operator {
+ color: #f92672;
+}
+
+.identifier {
+ color: #f5f5d8;
+}
+
+.token {
+ color: #f5f5d8;
+}
+
+.string {
+ color: #e6db74;
+}
Binary file static/img/grim-hacking.png has changed
Binary file static/img/grim-transparentish.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/index.html Sat May 26 17:38:15 2018 -0500
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
+ <script src="https://use.fontawesome.com/5854255963.js"></script>
+
+ <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet">
+ <link rel="stylesheet" type="text/css" href="/css/app.css">
+
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ </head>
+ <body>
+ <div id="app">
+ <div class="title-block">
+ <div class="name">{{name}}</div>
+ <div class="titles">
+ <div v-for="title in titles">{{title}}</div>
+ </div>
+ </div>
+ <div class="vcard-container">
+ <div class="vcard-wrapper">
+ <div class="vcard">
+ <div><span class="identifier">source</span> <span class="operator">=</span> <span class="token">{</span></div>
+ <div v-for="item in vcard">
+ &nbsp;&nbsp;<span class="string">&quot;<i v-bind:class="'fa fa-' + item.icon"></i>&quot;</span><span class="token">:</span> <span class="string">&quot;<a v-bind:href="item.href">{{item.text}}</a>&quot;</span><span class="token">,</span>
+ </div>
+ <div><span class="token">}</span></div>
+ </div>
+ </div>
+ </div>
+ <div class="reaper"></div>
+ </div>
+ <script src="/js/app.js"></script>
+ </body>
+</html>
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/js/app.js Sat May 26 17:38:15 2018 -0500
@@ -0,0 +1,50 @@
+var app = new Vue({
+ el: '#app',
+ data: {
+ name: "Gary Kramlich",
+ titles: [
+ "Open Source Developer",
+ "Twitch Affiliate",
+ "Pidgin Lead Developer",
+ "IM Freedom Secretary"
+ ],
+ vcard: [{
+ 'icon': 'bitbucket',
+ 'href': 'https://bitbucket.org/rw_grim',
+ 'text': 'rw_grim',
+ }, {
+ 'icon': 'envelope-o',
+ 'href': 'mailto:grim@reaperworld.com',
+ 'text': 'grim@reaperworld.com',
+ }, {
+ 'icon': 'github',
+ 'href': 'https://github.com/grimmy',
+ 'text': 'grimmy',
+ }, {
+ 'icon': 'reddit-alien',
+ 'href': 'https://www.reddit.com/user/rw_grim',
+ 'text': 'rw_grim',
+ }, {
+ 'icon': 'stack-overflow',
+ 'href': 'https://stackoverflow.com/users/852948/grim',
+ 'text': '852948',
+ }, {
+ 'icon': 'steam',
+ 'href': 'http://steamcommunity.com/id/rw_grim',
+ 'text': 'rw_grim',
+ }, {
+ 'icon': 'twitch',
+ 'href': 'https://twitch.tv/rw_grim',
+ 'text': 'rw_grim',
+ }, {
+ 'icon': 'twitter',
+ 'href': 'https://www.twitter.com/rw_grim',
+ 'text': 'rw_grim',
+ }, {
+ 'icon': 'youtube',
+ 'href': 'https://www.youtube.com/garykramlich',
+ 'text': 'garykramlich',
+ }]
+ },
+});
+