Skip to content

Commit

Permalink
Added basic JSON validation of the submitted configuration data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Hnatiw committed Aug 15, 2017
1 parent 3edfc95 commit 85232b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions main.go
Expand Up @@ -30,6 +30,14 @@ func main() {
// API endpoint to set the configuration options
func SetConfig(ctx *gin.Context) {
// Validate input
var config Configuration
if ctx.BindJSON(&config) != nil {
// Invalid JSON sent
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "invalid JSON",
})
return
}

// Send response
ctx.JSON(http.StatusOK, gin.H{
Expand Down
20 changes: 10 additions & 10 deletions racer.go
Expand Up @@ -41,20 +41,20 @@ func (err *RedirectError) Error() string {
// Proxy: *none*
// Targets: *none*
type Configuration struct {
Count int
Verbose bool
Proxy string
Targets []Target
Count int `json:"count"`
Verbose bool `json:"verbose"`
Proxy string `json:"proxy"`
Targets []Target `json:"targets" binding:"required"`
}

// Target is a struct to hold information about an individual target URL endpoint.
type Target struct {
Method string
URL string
Body string
Cookies []string
Headers []string
Redirects bool
Method string `json:"method" binding:"required"`
URL string `json:"url" binding:"required"`
Body string `json:"body"`
Cookies []string `json:"cookies"`
Headers []string `json:"headers"`
Redirects bool `json:"redirects"`
CookieJar http.CookieJar
}

Expand Down

0 comments on commit 85232b8

Please sign in to comment.