このコミットが含まれているのは:
守矢諏訪子 2023-05-19 11:53:02 +09:00
コミット dba933ece1
1個のファイルの変更42行の追加44行の削除

86
srv.go
ファイルの表示

@ -47,60 +47,58 @@ func serv (cnf Config, port int) {
_, _ = w.Write(buf)
})
http.HandleFunc("/archive", func(w http.ResponseWriter, r *http.Request) {
//lang := initloc(r)
pth := r.URL.Path
if !strings.HasSuffix(pth, "/") && !strings.HasSuffix(pth, "index.html") {
pth += "/index.html"
} else if strings.HasSuffix(pth, "/") && !strings.HasSuffix(pth, "index.html") {
pth += "index.html"
}
bdy, err := os.ReadFile(cnf.datapath + pth)
if err != nil {
http.Redirect(w, r, "/404", http.StatusSeeOther)
return
}
data.Body = string(bdy)
tmpl := template.Must(template.ParseFiles(cnf.webpath + "/view/archive.html"))
tmpl.Execute(w, data)
data = nil
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
lang := initloc(r)
data.Tit = getloc("top", lang)
data.Lan = lang
pth := r.URL.Path
data.Lan = lang
ftmpl[0] = cnf.webpath + "/view/index.html"
tmpl := template.Must(template.ParseFiles(ftmpl[0], ftmpl[1], ftmpl[2]))
if r.Method == "POST" {
err := r.ParseForm()
if err != nil { fmt.Println(err) }
if strings.HasPrefix(r.URL.Path, "/archive") {
if !strings.HasSuffix(pth, "/") && !strings.HasSuffix(pth, "index.html") {
pth += "/index.html"
} else if strings.HasSuffix(pth, "/") && !strings.HasSuffix(pth, "index.html") {
pth += "index.html"
}
// クッキー
if r.PostForm.Get("langchange") != "" {
cookie, err := r.Cookie("lang")
if err != nil || cookie.Value == "ja" {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "en", MaxAge: 31536000, Path: "/"})
} else {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "ja", MaxAge: 31536000, Path: "/"})
}
http.Redirect(w, r, "/", http.StatusSeeOther)
bdy, err := os.ReadFile(cnf.datapath + pth)
if err != nil {
http.Redirect(w, r, "/404", http.StatusSeeOther)
return
}
if r.PostForm.Get("hozonsite") != "" {
url := r.PostForm.Get("hozonsite")
// HTTPかHTTPSじゃない場合
if !checkprefix(url) {
data.Err = getloc("errfuseiurl", lang)
ftmpl[0] = cnf.webpath + "/view/404.html"
} else {
//if r.PostForm.Get("sosin") != "" {}
data.Body = string(bdy)
tmpl = template.Must(template.ParseFiles(cnf.webpath + "/view/archive.html"))
tmpl.Execute(w, data)
data = nil
} else {
data.Tit = getloc("top", lang)
if r.Method == "POST" {
err := r.ParseForm()
if err != nil { fmt.Println(err) }
// クッキー
if r.PostForm.Get("langchange") != "" {
cookie, err := r.Cookie("lang")
if err != nil || cookie.Value == "ja" {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "en", MaxAge: 31536000, Path: "/"})
} else {
http.SetCookie(w, &http.Cookie {Name: "lang", Value: "ja", MaxAge: 31536000, Path: "/"})
}
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
if r.PostForm.Get("hozonsite") != "" {
url := r.PostForm.Get("hozonsite")
// HTTPかHTTPSじゃない場合
if !checkprefix(url) {
data.Err = getloc("errfuseiurl", lang)
ftmpl[0] = cnf.webpath + "/view/404.html"
} else {
//if r.PostForm.Get("sosin") != "" {}
}
}
}
}