-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete re-factor of Peekaboo, added caching, gui written in AngularJS
- Loading branch information
Michael Persson
committed
Mar 28, 2016
1 parent
73ba2f9
commit fdcf8e7
Showing
204 changed files
with
7,608 additions
and
26,757 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Self containerd Dev. environment | ||
# docker run -it --rm -v $HOME/go:/root/go -v /var/run/docker.sock:/var/run/docker.sock -p 5050:5050 <image id> | ||
|
||
FROM centos:centos7 | ||
|
||
RUN set -ex ;\ | ||
yum install -y go vim-enhanced net-tools lsb lvm2 docker ;\ | ||
yum clean all | ||
|
||
ENV GOPATH=/root/go | ||
ENV PATH=${PATH}:${GOPATH}/bin | ||
ENV PROJECT=${GOPATH}/src/github.com/imc-trading/peekaboo | ||
|
||
RUN go get github.com/constabulary/gb/... | ||
|
||
EXPOSE 5050 | ||
|
||
WORKDIR ${PROJECT} | ||
ENTRYPOINT /bin/bash |
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,15 +1,15 @@ | ||
Peekaboo | ||
Peekaboo | ||
|
||
Copyright (c) 2015, IMC Trading B.V. | ||
Copyright (c) 2015, IMC Trading B.V. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
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
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,85 @@ | ||
package daemon | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
"github.com/imc-trading/peekaboo/log" | ||
) | ||
|
||
var apiURL = "/api/v1" | ||
|
||
type Daemon interface { | ||
Run(string, string) error | ||
} | ||
|
||
type daemon struct { | ||
data map[string]interface{} | ||
cache map[string]cache | ||
router *mux.Router | ||
} | ||
|
||
type cache struct { | ||
LastUpdated time.Time `json:"lastUpdated"` | ||
Timeout int `json:"timeoutSec"` | ||
FromCache bool `json:"fromCache"` | ||
} | ||
|
||
func (d *daemon) addStaticRoute(endpoint, path string) { | ||
endpoint = strings.TrimRight(endpoint, "/") + "/" | ||
log.Infof("Add static endpoint: %s path: %s", endpoint, path) | ||
d.router.PathPrefix(endpoint).Handler(http.StripPrefix(endpoint, http.FileServer(http.Dir(path)))) | ||
http.Handle(endpoint, d.router) | ||
} | ||
|
||
func (d *daemon) funcAPIRoute(endpoint string, getHwType func() (interface{}, error)) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
// Initialize or refresh cache when it has expired. | ||
expire := d.cache[endpoint].LastUpdated.Add(time.Duration(d.cache[endpoint].Timeout) * time.Second) | ||
if strings.ToLower(r.URL.Query().Get("refresh")) == "true" || d.cache[endpoint].LastUpdated.IsZero() || expire.Before(time.Now()) { | ||
var err error | ||
d.data[endpoint], err = getHwType() | ||
if err != nil { | ||
writeJSONError(w, r, d.data[endpoint], err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
d.cache[endpoint] = cache{ | ||
Timeout: d.cache[endpoint].Timeout, | ||
LastUpdated: time.Now(), | ||
FromCache: false, | ||
} | ||
|
||
writeJSON(w, r, d.data[endpoint], d.cache[endpoint]) | ||
return | ||
} | ||
|
||
d.cache[endpoint] = cache{ | ||
Timeout: d.cache[endpoint].Timeout, | ||
LastUpdated: d.cache[endpoint].LastUpdated, | ||
FromCache: true, | ||
} | ||
|
||
writeJSON(w, r, d.data[endpoint], d.cache[endpoint]) | ||
return | ||
} | ||
} | ||
|
||
func (d *daemon) addAPIRoute(endpoint string, getHwType func() (interface{}, error)) { | ||
log.Infof("Add API endpoint: %s method: GET", endpoint) | ||
d.router.HandleFunc(endpoint, d.funcAPIRoute(endpoint, getHwType)).Methods("GET") | ||
} | ||
|
||
/* | ||
func (d *daemon) addAPIPurgeRoute(endpoint string, getHwType func() (interface{}, error)) { | ||
log.Infof("Add API purge cache endpoint: %s method: PURGE", endpoint) | ||
d.router.HandleFunc(endpoint, d.funcAPIRoute(endpoint).Methods("PURGE") | ||
} | ||
func apiPurgeCache(forceUpdate func() error) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
} | ||
} | ||
*/ |
Oops, something went wrong.