rename debug mode to devel

This commit is contained in:
Ted Unangst 2022-02-28 20:40:23 -05:00
parent 24f78ccd65
commit c947c99f8a
9 changed files with 34 additions and 35 deletions

View File

@ -56,7 +56,7 @@ func friendorfoe(ct string) bool {
return false return false
} }
var debugClient = &http.Client{ var develClient = &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: true,
@ -70,8 +70,8 @@ func PostJunk(keyname string, key httpsig.PrivateKey, url string, j junk.Junk) e
func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) error { func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) error {
client := http.DefaultClient client := http.DefaultClient
if debugMode { if develMode {
client = debugClient client = develClient
} }
req, err := http.NewRequest("POST", url, bytes.NewReader(msg)) req, err := http.NewRequest("POST", url, bytes.NewReader(msg))
if err != nil { if err != nil {
@ -129,8 +129,8 @@ var flightdeck = gate.NewSerializer()
func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) { func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
client := http.DefaultClient client := http.DefaultClient
if debugMode { if develMode {
client = debugClient client = develClient
} }
fn := func() (interface{}, error) { fn := func() (interface{}, error) {
at := thefakename at := thefakename
@ -156,8 +156,8 @@ func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
func fetchsome(url string) ([]byte, error) { func fetchsome(url string) ([]byte, error) {
client := http.DefaultClient client := http.DefaultClient
if debugMode { if develMode {
client = debugClient client = develClient
} }
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {

View File

@ -37,7 +37,7 @@ func servewonkles(w http.ResponseWriter, r *http.Request) {
for _, l := range strings.Split(wonkles, "\n") { for _, l := range strings.Split(wonkles, "\n") {
words = append(words, l) words = append(words, l)
} }
if !debugMode { if !develMode {
w.Header().Set("Cache-Control", "max-age=7776000") w.Header().Set("Cache-Control", "max-age=7776000")
} }

View File

@ -174,10 +174,9 @@ Be mindful of what other services may be exposed via localhost or the
local network. local network.
.Ss Debug .Ss Debug
Debug mode may be enabled or disabled by running Debug mode may be enabled or disabled by running
.Ic debug Ar on|off . .Ic devel Ar on|off .
In debug mode, secure cookies are disabled and templates are reloaded In devel mode, secure cookies are disabled, TLS certs are not verified,
every request. and templates are reloaded every request.
Debug mode is really more useful for development, not debugging production.
.Ss Import .Ss Import
Data may be imported and converted from other services using the Data may be imported and converted from other services using the
.Ic import .Ic import

2
go.mod
View File

@ -10,5 +10,5 @@ require (
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 // indirect golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 // indirect
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
humungus.tedunangst.com/r/go-sqlite3 v1.1.3 humungus.tedunangst.com/r/go-sqlite3 v1.1.3
humungus.tedunangst.com/r/webs v0.6.49 humungus.tedunangst.com/r/webs v0.6.50
) )

4
go.sum
View File

@ -24,5 +24,5 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI=
humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M=
humungus.tedunangst.com/r/webs v0.6.49 h1:Tv3Fx2xnv+TINW5gepCpaDP+xhkOWlWp3rYE9FAkP50= humungus.tedunangst.com/r/webs v0.6.50 h1:MScU6TwnaluLUuyveARr43iXJkv2xeyAWBKea+5tnLA=
humungus.tedunangst.com/r/webs v0.6.49/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= humungus.tedunangst.com/r/webs v0.6.50/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps=

10
honk.go
View File

@ -318,7 +318,7 @@ func main() {
serverPrefix = fmt.Sprintf("https://%s/", serverName) serverPrefix = fmt.Sprintf("https://%s/", serverName)
getconfig("usersep", &userSep) getconfig("usersep", &userSep)
getconfig("honksep", &honkSep) getconfig("honksep", &honkSep)
getconfig("debug", &debugMode) getconfig("devel", &develMode)
prepareStatements(db) prepareStatements(db)
switch cmd { switch cmd {
case "admin": case "admin":
@ -328,15 +328,15 @@ func main() {
elog.Fatal("import username mastodon|twitter srcdir") elog.Fatal("import username mastodon|twitter srcdir")
} }
importMain(args[1], args[2], args[3]) importMain(args[1], args[2], args[3])
case "debug": case "devel":
if len(args) != 2 { if len(args) != 2 {
elog.Fatal("need an argument: debug (on|off)") elog.Fatal("need an argument: devel (on|off)")
} }
switch args[1] { switch args[1] {
case "on": case "on":
setconfig("debug", 1) setconfig("devel", 1)
case "off": case "off":
setconfig("debug", 0) setconfig("devel", 0)
default: default:
elog.Fatal("argument must be on or off") elog.Fatal("argument must be on or off")
} }

View File

@ -67,9 +67,9 @@ func upgradedb() {
setconfig("loginmsg", "<h2>login</h2>") setconfig("loginmsg", "<h2>login</h2>")
} }
d := -1 d := -1
getconfig("debug", &d) getconfig("devel", &d)
if d == -1 { if d == -1 {
setconfig("debug", 0) setconfig("devel", 0)
} }
doordie(db, "update config set value = 27 where key = 'dbversion'") doordie(db, "update config set value = 27 where key = 'dbversion'")
fallthrough fallthrough

View File

@ -158,7 +158,7 @@ func initdb() {
setconfig("servermsg", "<h2>Things happen.</h2>") setconfig("servermsg", "<h2>Things happen.</h2>")
setconfig("aboutmsg", "<h3>What is honk?</h3><p>Honk is amazing!") setconfig("aboutmsg", "<h3>What is honk?</h3><p>Honk is amazing!")
setconfig("loginmsg", "<h2>login</h2>") setconfig("loginmsg", "<h2>login</h2>")
setconfig("debug", 0) setconfig("devel", 0)
db.Close() db.Close()
fmt.Printf("done.\n") fmt.Printf("done.\n")

24
web.go
View File

@ -47,7 +47,7 @@ var readviews *templates.Template
var userSep = "u" var userSep = "u"
var honkSep = "h" var honkSep = "h"
var debugMode = false var develMode = false
func getuserstyle(u *login.UserInfo) template.CSS { func getuserstyle(u *login.UserInfo) template.CSS {
if u == nil { if u == nil {
@ -235,7 +235,7 @@ func showrss(w http.ResponseWriter, r *http.Request) {
modtime = honk.Date modtime = honk.Date
} }
} }
if !debugMode { if !develMode {
w.Header().Set("Cache-Control", "max-age=300") w.Header().Set("Cache-Control", "max-age=300")
w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat)) w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat))
} }
@ -862,7 +862,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
sort.Slice(onts, func(i, j int) bool { sort.Slice(onts, func(i, j int) bool {
return onts[i].Name < onts[j].Name return onts[i].Name < onts[j].Name
}) })
if u == nil && !debugMode { if u == nil && !develMode {
w.Header().Set("Cache-Control", "max-age=300") w.Header().Set("Cache-Control", "max-age=300")
} }
templinfo := getInfo(r) templinfo := getInfo(r)
@ -1085,7 +1085,7 @@ func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo
templinfo["TopHID"] = 0 templinfo["TopHID"] = 0
} }
} }
if u == nil && !debugMode { if u == nil && !develMode {
w.Header().Set("Cache-Control", "max-age=60") w.Header().Set("Cache-Control", "max-age=60")
} }
err := readviews.Execute(w, "honkpage.html", templinfo) err := readviews.Execute(w, "honkpage.html", templinfo)
@ -2125,20 +2125,20 @@ func somedays() string {
} }
func avatate(w http.ResponseWriter, r *http.Request) { func avatate(w http.ResponseWriter, r *http.Request) {
if debugMode { if develMode {
loadAvatarColors() loadAvatarColors()
} }
n := r.FormValue("a") n := r.FormValue("a")
hex := r.FormValue("hex") == "1" hex := r.FormValue("hex") == "1"
a := genAvatar(n, hex) a := genAvatar(n, hex)
if !debugMode { if !develMode {
w.Header().Set("Cache-Control", "max-age="+somedays()) w.Header().Set("Cache-Control", "max-age="+somedays())
} }
w.Write(a) w.Write(a)
} }
func serveasset(w http.ResponseWriter, r *http.Request) { func serveasset(w http.ResponseWriter, r *http.Request) {
if !debugMode { if !develMode {
w.Header().Set("Cache-Control", "max-age=7776000") w.Header().Set("Cache-Control", "max-age=7776000")
} }
dir := viewDir dir := viewDir
@ -2149,7 +2149,7 @@ func serveasset(w http.ResponseWriter, r *http.Request) {
} }
func servehelp(w http.ResponseWriter, r *http.Request) { func servehelp(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"] name := mux.Vars(r)["name"]
if !debugMode { if !develMode {
w.Header().Set("Cache-Control", "max-age=3600") w.Header().Set("Cache-Control", "max-age=3600")
} }
http.ServeFile(w, r, viewDir+"/docs/"+name) http.ServeFile(w, r, viewDir+"/docs/"+name)
@ -2163,7 +2163,7 @@ func servehtml(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/about" { if r.URL.Path == "/about" {
templinfo["Sensors"] = getSensors() templinfo["Sensors"] = getSensors()
} }
if u == nil && !debugMode { if u == nil && !develMode {
w.Header().Set("Cache-Control", "max-age=60") w.Header().Set("Cache-Control", "max-age=60")
} }
err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo) err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
@ -2433,7 +2433,7 @@ func bgmonitor() {
func serve() { func serve() {
db := opendatabase() db := opendatabase()
login.Init(login.InitArgs{Db: db, Logger: ilog}) login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode})
listener, err := openListener() listener, err := openListener()
if err != nil { if err != nil {
@ -2447,7 +2447,7 @@ func serve() {
loadLingo() loadLingo()
w100 := wait100ms() w100 := wait100ms()
readviews = templates.Load(debugMode, readviews = templates.Load(develMode,
viewDir+"/views/honkpage.html", viewDir+"/views/honkpage.html",
viewDir+"/views/honkfrags.html", viewDir+"/views/honkfrags.html",
viewDir+"/views/honkers.html", viewDir+"/views/honkers.html",
@ -2466,7 +2466,7 @@ func serve() {
viewDir+"/views/onts.html", viewDir+"/views/onts.html",
viewDir+"/views/honkpage.js", viewDir+"/views/honkpage.js",
) )
if !debugMode { if !develMode {
assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"} assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"}
for _, s := range assets { for _, s := range assets {
savedassetparams[s] = getassetparam(s) savedassetparams[s] = getassetparam(s)