Skip to content

Commit

Permalink
fixed bugs, increased version
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Hener committed Feb 28, 2022
1 parent b886ac2 commit b45ddef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
18 changes: 17 additions & 1 deletion internal/myclipboard/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package myclipboard
import (
"encoding/json"
"time"

"github.com/patrickhener/goshs/internal/mylog"
)

// Clipboard is the in memory clipboard to hold the copy-pasteable content
Expand Down Expand Up @@ -49,7 +51,8 @@ func (c *Clipboard) AddEntry(con string) error {
func (c *Clipboard) DeleteEntry(id int) error {
entries := c.Entries
entries = append(entries[:id], entries[id+1:]...)
c.Entries = entries
newEntries := reindex(entries)
c.Entries = newEntries
return nil
}

Expand All @@ -74,3 +77,16 @@ func (c *Clipboard) Download() ([]byte, error) {
}
return e, nil
}

func reindex(entries []Entry) []Entry {
var newEntries []Entry
for i, e := range entries {
mylog.Debugf("Entry #%d: %+v\n", i, e)
newEntries = append(newEntries, Entry{
ID: i,
Content: e.Content,
Time: e.Time,
})
}
return newEntries
}
6 changes: 5 additions & 1 deletion internal/myhttp/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,13 @@ func (fs *FileServer) handler(w http.ResponseWriter, req *http.Request) {
if upath == "/favicon.ico" {
return
}
upath = path.Clean(upath)
upath = filepath.Clean(upath)

mylog.Debugf("Cleaned upath is: %+v", upath)

// Define absolute path
open := fs.Webroot + path.Clean(upath)
open := fs.Webroot + upath

// Check if you are in a dir
// disable G304 (CWE-22): Potential file inclusion via variable
Expand Down
4 changes: 1 addition & 3 deletions internal/mylog/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mylog

import (
"fmt"
"net/http"
"os"

Expand All @@ -15,10 +14,9 @@ func LogRequest(req *http.Request, status int) {
return
}
logger.Infof("%s - - \"%s %s %s\" - %+v", req.RemoteAddr, req.Method, req.URL, req.Proto, status)
fmt.Println(req.URL.Query())
if req.URL.Query() != nil {
for k, v := range req.URL.Query() {
logger.Infof("Parameter %s is %s", k, v)
logger.Debugf("Parameter %s is %s", k, v)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/patrickhener/goshs/internal/myutils"
)

const goshsVersion = "v0.1.6"
const goshsVersion = "v0.1.7"

var (
port = 8000
Expand Down

0 comments on commit b45ddef

Please sign in to comment.