Skip to content

Commit

Permalink
0.8.1 issue #17 fixed + change logs path for easier backups
Browse files Browse the repository at this point in the history
  • Loading branch information
jolav committed Feb 11, 2023
1 parent 7e95e34 commit 3a83832
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"net/http"
"os"
"os/user"
"strings"
"time"

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
//////////

Expand All @@ -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()
Expand Down
10 changes: 7 additions & 3 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 /
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion www/_public/templates/version.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h2 class="centerText">
API doc
<small>
<small>(version 0.8.0)</small>
<small>(version 0.8.1)</small>
</small>
</h2>
<!-- End -->

0 comments on commit 3a83832

Please sign in to comment.