Skip to content

Commit

Permalink
latest version: v0.5.12
Browse files Browse the repository at this point in the history
  • Loading branch information
alexj212 committed Feb 24, 2023
1 parent 1c3ce01 commit c31e192
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func InitializeDB() (*bolt.DB, error) {

fmt.Printf("Opened dumpr.db data file\n")

db.Update(func(tx *bolt.Tx) error {
_ = db.Update(func(tx *bolt.Tx) error {
_, _ = tx.CreateBucket([]byte(SessionBucket))
// ignore bucket already created error
return nil
Expand All @@ -59,7 +59,7 @@ func InitializeDB() (*bolt.DB, error) {
// empty bucket on first call.
responses := CreateDefaultRules()
for _, val := range responses {
StoreResponder(val)
_ = StoreResponder(val)
}

}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
dumpr:
image: ghcr.io/alexj212/dumpr:latest
container_name: dumpr
command: /app/dumpr --webDir=/app/web --publicUrl=https://dumpr.io --publicBinEndpoint=dumpr.io:48081
command: /app/dumpr --publicUrl=https://dumpr.io --publicBinEndpoint=dumpr.io:48081
ports:
- "48080:8080"
- "48081:8081"
Expand Down
11 changes: 5 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ var (
// OsSignal signal used to shut down
OsSignal chan os.Signal

saveDir = goopt.String([]string{"--saveDir"}, "/tmp", "save directory")
webDir = goopt.String([]string{"--webDir"}, "./web", "web assets directory")
//quiet = goopt.Flag([]string{"--quiet"}, []string{}, "silently log to file", "")
saveDir = goopt.String([]string{"--saveDir"}, "/tmp", "save directory")
webDir = goopt.String([]string{"--webDir"}, "./web", "web assets directory")
serverHost = goopt.String([]string{"--host"}, "0.0.0.0", "host for server")
publicUrl = goopt.String([]string{"--publicUrl"}, "http://127.0.0.1:8080", "public url")
publicBinEndpoint = goopt.String([]string{"--publicBinEndpoint"}, "127.0.0.1:8081", "public url")
Expand All @@ -64,7 +63,7 @@ var (
staticDirHTTPFS http.FileSystem

m melody.Melody
duraFormatOveride durafmt.Units
duraFormatOverride durafmt.Units
purgeOlderThan *durafmt.Durafmt
maxSessionSize int
maxSessionSizeFormatted string
Expand Down Expand Up @@ -99,7 +98,7 @@ dumpr
goopt.Parse(nil)

var err error
duraFormatOveride, err = durafmt.DefaultUnitsCoder.Decode("y:y,w:w,d:d,h:h,m:m,s:s,ms:ms,μs:μs")
duraFormatOverride, err = durafmt.DefaultUnitsCoder.Decode("y:y,w:w,d:d,h:h,m:m,s:s,ms:ms,μs:μs")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -206,7 +205,7 @@ func main() {
})
}

// LaunchSessionReaper launches the session reaper that will cleanup sessions older than purgeOlderThan option.
// LaunchSessionReaper launches the session reaper that will clean up sessions older than purgeOlderThan option.
func LaunchSessionReaper() {
fmt.Printf("launching cleanup process, will delete sessions older than %v\n", purgeOlderThan)

Expand Down
11 changes: 5 additions & 6 deletions responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sort"
)

// AutoResponses struct to store map of rules and ordered list to be chcked when requests come in
// AutoResponses struct to store map of rules and ordered list to be checked when requests come in
type AutoResponses struct {
m map[string]*AutoResponse
l []*AutoResponse
Expand Down Expand Up @@ -60,11 +60,10 @@ func (r *AutoResponses) Get(name string) (*AutoResponse, bool) {
return val, ok
}

// Delete delete the AutoResponse from the list of AutoResponders
func (r *AutoResponses) Delete(name string) bool {
// Delete the AutoResponse from the list of AutoResponders
func (r *AutoResponses) Delete(name string) error {
delete(r.m, name)
r.Save()
return true
return r.Save()
}

// Update update an AutoResponse
Expand Down Expand Up @@ -119,7 +118,7 @@ type AutoResponse struct {
ContentType string `yaml:"content_type" json:"content_type"`
Response string `yaml:"response" json:"response"`
ResponseHeaders map[string]string `yaml:"responseHeaders" json:"response_headers"`
pathRegex *regexp.Regexp `yaml:"-" json:"-"`
pathRegex *regexp.Regexp
}

// Bytes returns the bytes of the json formatted of the AutoResponse
Expand Down
24 changes: 10 additions & 14 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hako/durafmt"
"gopkg.in/olahol/melody.v1"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
Expand All @@ -30,9 +29,6 @@ const (

// HTTP enum to define http protocol
HTTP = 1

// UNKNOWN enum to define unknown protocol
UNKNOWN Protocol = 2
)

var (
Expand Down Expand Up @@ -109,12 +105,12 @@ type Session struct {
Viewers []*melody.Session `json:"-"`
Protocol Protocol `json:"protocol"`
MultiPartFiles map[string]*MultiPartFile `json:"multipartFiles"`
outputFile *os.File `json:"-"`
Active bool `json:"active"`
HTTPMethod string `json:"httpMethod"`
HTTPPath string `json:"httpPath"`
HandledByRule string `json:"handled_by_rule"`
HTTPSession *HTTPRequestJSON `json:"-"`
outputFile *os.File
Active bool `json:"active"`
HTTPMethod string `json:"httpMethod"`
HTTPPath string `json:"httpPath"`
HandledByRule string `json:"handled_by_rule"`
HTTPSession *HTTPRequestJSON `json:"-"`
}

// ApiSession struct to store details of a session to be returned via web service in json form
Expand Down Expand Up @@ -170,14 +166,14 @@ func (s *Session) AgeMs() int64 {
func (s *Session) Age() string {
d := time.Now().Sub(s.StartTime)
duration := durafmt.Parse(d)
return duration.Format(duraFormatOveride)
return duration.Format(duraFormatOverride)
}

// SessionActiveTime returns the duration of session in human-readable format
func (s *Session) SessionActiveTime() string {
d := s.EndTime.Sub(s.StartTime)
duration := durafmt.Parse(d)
return duration.Format(duraFormatOveride)
return duration.Format(duraFormatOverride)
}

// FormattedStartTime returns formatted start time
Expand Down Expand Up @@ -207,7 +203,7 @@ func (s *Session) Description() string {
duration := durafmt.Parse(d)

// fmt.Printf("%v - %v = %v / %v\n", s.EndTime, s.StartTime, d, duration)
sb.WriteString(fmt.Sprintf(" Session Life: %s", duration.Format(duraFormatOveride)))
sb.WriteString(fmt.Sprintf(" Session Life: %s", duration.Format(duraFormatOverride)))
}
return sb.String()
}
Expand Down Expand Up @@ -316,7 +312,7 @@ func (s *Session) LoadHTTPRequestJSON() error {
return fmt.Errorf("not a http protocol based session")
}

httpSessionBytes, err := ioutil.ReadFile(s.SaveFile)
httpSessionBytes, err := os.ReadFile(s.SaveFile)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.11
0.5.12
9 changes: 4 additions & 5 deletions webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"gopkg.in/olahol/melody.v1"
"html/template"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -123,7 +122,7 @@ func GinServer() (err error) {
return "", fmt.Errorf("ViewEngine tplFileName:%v error: %v", tplFileName, err)
}

data, err := ioutil.ReadAll(tplFile)
data, err := io.ReadAll(tplFile)
if err != nil {
return "", fmt.Errorf("ViewEngine render read name:%v, error: %v", tplFileName, err)
}
Expand Down Expand Up @@ -204,12 +203,12 @@ func GinServer() (err error) {
return
}

success := autoResponders.Delete(name)
if !success {
err := autoResponders.Delete(name)
if err != nil {
payload := gin.H{
"result": "failed",
"code": "AutoResponder-NOT-FOUND",
"message": fmt.Sprintf("DeleteAutoResponder [%s] returned false", name),
"message": fmt.Sprintf("DeleteAutoResponder [%s] error: %v", name, err),
}
ctx.JSON(404, payload)
return
Expand Down

0 comments on commit c31e192

Please sign in to comment.