diff --git a/README.md b/README.md index 2e31cce..d9e6440 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -![Version](https://img.shields.io/badge/version-0.8.0-orange.svg) +![Version](https://img.shields.io/badge/version-0.8.1-orange.svg) ![Maintained YES](https://img.shields.io/badge/Maintained%3F-yes-green.svg) ![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg) # ![logo](https://github.com/jolav/codetabs/blob/master/www/_public/icons/ct/ct64r.png?raw=true) **ONLINE TOOLS ([codetabs.com](https://codetabs.com))** -**version 0.8.0** +**version 0.8.1** 1. [Count LOC (lines of code) online from github/gitlab repos or zipped uploaded folder](#count-loc-online) 2. [CORS proxy](#cors-proxy) diff --git a/main.go b/main.go index a077a46..ddd234f 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "log" "net/http" "os" + "os/user" "strings" "time" @@ -18,14 +19,14 @@ import ( gl "github.com/jolav/codetabs/geolocation" he "github.com/jolav/codetabs/headers" lo "github.com/jolav/codetabs/loc" - px "github.com/jolav/codetabs/proxy" + "github.com/jolav/codetabs/proxy" st "github.com/jolav/codetabs/stars" "github.com/jolav/codetabs/store" vg "github.com/jolav/codetabs/video2gif" we "github.com/jolav/codetabs/weather" ) -var version = "0.8.0" +var version = "0.8.1" var when = "undefined" type Conf struct { @@ -53,13 +54,22 @@ func main() { } store.MyDB = db - // Custom Error Log File + Custom Hits Log File + // + usernow, err := user.Current() + if err != nil { + log.Fatal(err) + } + + // Custom Error Log File var mylog *os.File + c.ErrorsLogFile = usernow.HomeDir + c.ErrorsLogFile if c.Mode == "production" { mylog = u.CreateCustomErrorLogFile(c.ErrorsLogFile) } defer mylog.Close() + // Custom Hits Log File + c.HitsLogFile = usernow.HomeDir + c.HitsLogFile c.hitsLog = u.NewHitsFile(c.HitsLogFile) ////////// @@ -72,7 +82,6 @@ func main() { weather := we.NewWeather(false) video2gif := vg.NewVideo2Gif(false) stars := st.NewStars(false) - proxy := px.NewProxy(false) loc := lo.NewLoc(false) mux := http.NewServeMux() diff --git a/proxy/proxy.go b/proxy/proxy.go index 04ebf59..0bd082a 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -18,7 +18,7 @@ type proxy struct { quest string } -func (p *proxy) Router(w http.ResponseWriter, r *http.Request) { +func Router(w http.ResponseWriter, r *http.Request) { params := strings.Split(strings.ToLower(r.URL.Path), "/") path := params[1:len(params)] if path[len(path)-1] == "" { // remove last empty slot after / @@ -29,6 +29,8 @@ func (p *proxy) Router(w http.ResponseWriter, r *http.Request) { u.BadRequest(w, r) return } + + p := newProxy(false) r.ParseForm() p.quest = r.Form.Get("quest") if p.quest == "" || len(path) != 2 { @@ -82,7 +84,9 @@ func (p *proxy) doProxyRequest(w http.ResponseWriter, r *http.Request) { } } -func NewProxy(test bool) proxy { - p := proxy{} +func newProxy(test bool) proxy { + p := proxy{ + quest: "", + } return p } diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index ca7292d..0723ec5 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -16,7 +16,7 @@ func TestProxyApi(t *testing.T) { validFormat = "Bad request, valid format is 'api.codetabs.com/v1/{service}?{param}=value' .Please read our docs at https://codetabs.com" ) - p := NewProxy(true) + //p := newProxy(true) type proxyTestOutput struct { StatusCode int // `json:"statusCode"` @@ -60,7 +60,7 @@ func TestProxyApi(t *testing.T) { } if pass { rr := httptest.NewRecorder() - handler := http.HandlerFunc(p.Router) + handler := http.HandlerFunc(Router) handler.ServeHTTP(rr, req) if rr.Code != test.statusCode { t.Errorf("%s got %v want %v\n", test.endpoint, rr.Code, test.statusCode) diff --git a/www/_public/templates/version.html b/www/_public/templates/version.html index c4b19ec..89d5408 100644 --- a/www/_public/templates/version.html +++ b/www/_public/templates/version.html @@ -2,7 +2,7 @@

API doc - (version 0.8.0) + (version 0.8.1)