Skip to content

Commit 3a83832

Browse files
committed
0.8.1 issue #17 fixed + change logs path for easier backups
1 parent 7e95e34 commit 3a83832

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
![Version](https://img.shields.io/badge/version-0.8.0-orange.svg)
2+
![Version](https://img.shields.io/badge/version-0.8.1-orange.svg)
33
![Maintained YES](https://img.shields.io/badge/Maintained%3F-yes-green.svg)
44
![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)
55

66
# ![logo](https://github.com/jolav/codetabs/blob/master/www/_public/icons/ct/ct64r.png?raw=true) **ONLINE TOOLS ([codetabs.com](https://codetabs.com))**
77

8-
**version 0.8.0**
8+
**version 0.8.1**
99

1010
1. [Count LOC (lines of code) online from github/gitlab repos or zipped uploaded folder](#count-loc-online)
1111
2. [CORS proxy](#cors-proxy)

main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"log"
1111
"net/http"
1212
"os"
13+
"os/user"
1314
"strings"
1415
"time"
1516

@@ -18,14 +19,14 @@ import (
1819
gl "github.com/jolav/codetabs/geolocation"
1920
he "github.com/jolav/codetabs/headers"
2021
lo "github.com/jolav/codetabs/loc"
21-
px "github.com/jolav/codetabs/proxy"
22+
"github.com/jolav/codetabs/proxy"
2223
st "github.com/jolav/codetabs/stars"
2324
"github.com/jolav/codetabs/store"
2425
vg "github.com/jolav/codetabs/video2gif"
2526
we "github.com/jolav/codetabs/weather"
2627
)
2728

28-
var version = "0.8.0"
29+
var version = "0.8.1"
2930
var when = "undefined"
3031

3132
type Conf struct {
@@ -53,13 +54,22 @@ func main() {
5354
}
5455
store.MyDB = db
5556

56-
// Custom Error Log File + Custom Hits Log File
57+
//
58+
usernow, err := user.Current()
59+
if err != nil {
60+
log.Fatal(err)
61+
}
62+
63+
// Custom Error Log File
5764
var mylog *os.File
65+
c.ErrorsLogFile = usernow.HomeDir + c.ErrorsLogFile
5866
if c.Mode == "production" {
5967
mylog = u.CreateCustomErrorLogFile(c.ErrorsLogFile)
6068
}
6169
defer mylog.Close()
6270

71+
// Custom Hits Log File
72+
c.HitsLogFile = usernow.HomeDir + c.HitsLogFile
6373
c.hitsLog = u.NewHitsFile(c.HitsLogFile)
6474
//////////
6575

@@ -72,7 +82,6 @@ func main() {
7282
weather := we.NewWeather(false)
7383
video2gif := vg.NewVideo2Gif(false)
7484
stars := st.NewStars(false)
75-
proxy := px.NewProxy(false)
7685
loc := lo.NewLoc(false)
7786

7887
mux := http.NewServeMux()

proxy/proxy.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type proxy struct {
1818
quest string
1919
}
2020

21-
func (p *proxy) Router(w http.ResponseWriter, r *http.Request) {
21+
func Router(w http.ResponseWriter, r *http.Request) {
2222
params := strings.Split(strings.ToLower(r.URL.Path), "/")
2323
path := params[1:len(params)]
2424
if path[len(path)-1] == "" { // remove last empty slot after /
@@ -29,6 +29,8 @@ func (p *proxy) Router(w http.ResponseWriter, r *http.Request) {
2929
u.BadRequest(w, r)
3030
return
3131
}
32+
33+
p := newProxy(false)
3234
r.ParseForm()
3335
p.quest = r.Form.Get("quest")
3436
if p.quest == "" || len(path) != 2 {
@@ -82,7 +84,9 @@ func (p *proxy) doProxyRequest(w http.ResponseWriter, r *http.Request) {
8284
}
8385
}
8486

85-
func NewProxy(test bool) proxy {
86-
p := proxy{}
87+
func newProxy(test bool) proxy {
88+
p := proxy{
89+
quest: "",
90+
}
8791
return p
8892
}

proxy/proxy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestProxyApi(t *testing.T) {
1616
validFormat = "Bad request, valid format is 'api.codetabs.com/v1/{service}?{param}=value' .Please read our docs at https://codetabs.com"
1717
)
1818

19-
p := NewProxy(true)
19+
//p := newProxy(true)
2020

2121
type proxyTestOutput struct {
2222
StatusCode int // `json:"statusCode"`
@@ -60,7 +60,7 @@ func TestProxyApi(t *testing.T) {
6060
}
6161
if pass {
6262
rr := httptest.NewRecorder()
63-
handler := http.HandlerFunc(p.Router)
63+
handler := http.HandlerFunc(Router)
6464
handler.ServeHTTP(rr, req)
6565
if rr.Code != test.statusCode {
6666
t.Errorf("%s got %v want %v\n", test.endpoint, rr.Code, test.statusCode)

www/_public/templates/version.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h2 class="centerText">
33
API doc
44
<small>
5-
<small>(version 0.8.0)</small>
5+
<small>(version 0.8.1)</small>
66
</small>
77
</h2>
88
<!-- End -->

0 commit comments

Comments
 (0)