frontend: backend: clean up code for better readability
This commit is contained in:
parent
f84ee2a466
commit
32a37eea32
4 changed files with 39 additions and 97 deletions
5
go.mod
5
go.mod
|
|
@ -2,7 +2,10 @@ module ddServer
|
|||
|
||||
go 1.21.4
|
||||
|
||||
require github.com/stretchr/testify v1.8.4
|
||||
require (
|
||||
github.com/stretchr/testify v1.8.4
|
||||
golang.org/x/text v0.14.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -4,6 +4,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@ package handlers
|
|||
|
||||
import (
|
||||
"ddServer/model"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
// AddMonster is a http.HandlerFunc that adds a new monster to the Monsters slice.
|
||||
|
|
@ -64,80 +68,6 @@ func parseInt(s string) int {
|
|||
|
||||
// parseMonster parses the Monster from monsterForm.html and return it.
|
||||
func parseMonster(r *http.Request) model.Monster {
|
||||
var (
|
||||
acrobatics = ""
|
||||
animalHandling = ""
|
||||
arcana = ""
|
||||
athletics = ""
|
||||
deception = ""
|
||||
history = ""
|
||||
insight = ""
|
||||
intimidation = ""
|
||||
investigation = ""
|
||||
medicine = ""
|
||||
nature = ""
|
||||
performance = ""
|
||||
perception = ""
|
||||
persuasion = ""
|
||||
sleightOfHand = ""
|
||||
religion = ""
|
||||
stealth = ""
|
||||
survival = ""
|
||||
)
|
||||
if r.FormValue("checkAcrobatics") == "on" {
|
||||
acrobatics = r.FormValue("acrobatics")
|
||||
}
|
||||
if r.FormValue("checkAnimalHandling") == "on" {
|
||||
animalHandling = r.FormValue("animalHandling")
|
||||
}
|
||||
if r.FormValue("checkArcana") == "on" {
|
||||
arcana = r.FormValue("arcana")
|
||||
}
|
||||
if r.FormValue("checkAthletics") == "on" {
|
||||
athletics = r.FormValue("athletics")
|
||||
}
|
||||
if r.FormValue("checkDeception") == "on" {
|
||||
deception = r.FormValue("deception")
|
||||
}
|
||||
if r.FormValue("checkHistory") == "on" {
|
||||
history = r.FormValue("history")
|
||||
}
|
||||
if r.FormValue("checkInsight") == "on" {
|
||||
insight = r.FormValue("insight")
|
||||
}
|
||||
if r.FormValue("checkIntimidation") == "on" {
|
||||
intimidation = r.FormValue("intimidation")
|
||||
}
|
||||
if r.FormValue("checkInvestigation") == "on" {
|
||||
investigation = r.FormValue("investigation")
|
||||
}
|
||||
if r.FormValue("checkMedicine") == "on" {
|
||||
medicine = r.FormValue("medicine")
|
||||
}
|
||||
if r.FormValue("checkNature") == "on" {
|
||||
nature = r.FormValue("nature")
|
||||
}
|
||||
if r.FormValue("checkPerformance") == "on" {
|
||||
performance = r.FormValue("performance")
|
||||
}
|
||||
if r.FormValue("checkPerception") == "on" {
|
||||
perception = r.FormValue("perception")
|
||||
}
|
||||
if r.FormValue("checkPersuasion") == "on" {
|
||||
persuasion = r.FormValue("persuasion")
|
||||
}
|
||||
if r.FormValue("checkSleightOfHand") == "on" {
|
||||
sleightOfHand = r.FormValue("sleightOfHand")
|
||||
}
|
||||
if r.FormValue("checkStealth") == "on" {
|
||||
stealth = r.FormValue("stealth")
|
||||
}
|
||||
if r.FormValue("checkSurvival") == "on" {
|
||||
survival = r.FormValue("survival")
|
||||
}
|
||||
if r.FormValue("checkReligion") == "on" {
|
||||
religion = r.FormValue("religion")
|
||||
}
|
||||
return model.Monster{
|
||||
Name: r.FormValue("name"),
|
||||
Source: r.FormValue("source"),
|
||||
|
|
@ -176,24 +106,24 @@ func parseMonster(r *http.Request) model.Monster {
|
|||
Int: r.FormValue("saveInt"),
|
||||
},
|
||||
Skill: model.Skill{
|
||||
Perception: perception,
|
||||
Stealth: stealth,
|
||||
Acrobatics: acrobatics,
|
||||
AnimalHandling: animalHandling,
|
||||
Arcana: arcana,
|
||||
Athletics: athletics,
|
||||
Deception: deception,
|
||||
History: history,
|
||||
Insight: insight,
|
||||
Intimidation: intimidation,
|
||||
Investigation: investigation,
|
||||
Medicine: medicine,
|
||||
Nature: nature,
|
||||
Performance: performance,
|
||||
Persuasion: persuasion,
|
||||
SleightOfHand: sleightOfHand,
|
||||
Survival: survival,
|
||||
Religion: religion,
|
||||
Perception: checkCheckbox("perception", r),
|
||||
Stealth: checkCheckbox("stealth", r),
|
||||
Acrobatics: checkCheckbox("acrobatics", r),
|
||||
AnimalHandling: checkCheckbox("animalhandling", r),
|
||||
Arcana: checkCheckbox("arcana", r),
|
||||
Athletics: checkCheckbox("athletics", r),
|
||||
Deception: checkCheckbox("deception", r),
|
||||
History: checkCheckbox("history", r),
|
||||
Insight: checkCheckbox("insight", r),
|
||||
Intimidation: checkCheckbox("intimidation", r),
|
||||
Investigation: checkCheckbox("investigation", r),
|
||||
Medicine: checkCheckbox("medicine", r),
|
||||
Nature: checkCheckbox("nature", r),
|
||||
Performance: checkCheckbox("performance", r),
|
||||
Persuasion: checkCheckbox("persuasion", r),
|
||||
SleightOfHand: checkCheckbox("sleightofhand", r),
|
||||
Survival: checkCheckbox("survival", r),
|
||||
Religion: checkCheckbox("religion", r),
|
||||
},
|
||||
Resist: []string{r.FormValue("resist")},
|
||||
ConditionImmune: []string{r.FormValue("conditionImmune")},
|
||||
|
|
@ -216,3 +146,10 @@ func parseMonster(r *http.Request) model.Monster {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func checkCheckbox(field string, r *http.Request) string {
|
||||
if r.FormValue(fmt.Sprintf("check%v", cases.Caser(cases.Title(language.Und)).String(field))) == "on" {
|
||||
return r.FormValue(field)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,9 +85,9 @@
|
|||
</div>
|
||||
<div class="tile is-parent">
|
||||
<div class="tile is-child field">
|
||||
<label for="animalHandling" class="checkbox"><input type="checkbox" name="checkAnimalHandling">Animal Handling:</label>
|
||||
<label for="animalhandling" class="checkbox"><input type="checkbox" name="checkAnimalhandling">Animal Handling:</label>
|
||||
<div class="control">
|
||||
<input type="text" name="animalHandling" required class="input input-bordered w-full max-w-xs"
|
||||
<input type="text" name="animalhandling" required class="input input-bordered w-full max-w-xs"
|
||||
value="{{ .animalHandling }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -221,9 +221,9 @@
|
|||
<div class="tile is-ancestor">
|
||||
<div class="tile is-parent">
|
||||
<div class="tile is-child field">
|
||||
<label for="sleightOfHand" class="checkbox"><input type="checkbox" name="checkSleightOfHand">Sleight of Hand:</label>
|
||||
<label for="sleightofhand" class="checkbox"><input type="checkbox" name="checkSleightofhand">Sleight of Hand:</label>
|
||||
<div class="control">
|
||||
<input type="text" name="sleightOfHand" required class="input input-bordered w-full max-w-xs"
|
||||
<input type="text" name="sleightofhand" required class="input input-bordered w-full max-w-xs"
|
||||
value="{{.sleightOfHand }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue