バグを修正

このコミットが含まれているのは:
守矢諏訪子 2023-07-04 10:03:52 +09:00
コミット 1c1de3c8d5
5個のファイルの変更27行の追加6行の削除

ファイルの表示

@ -1,4 +1,7 @@
# 2.1.0(未公開)
# 2.1.1
* バグを修正
# 2.1.0
* ローカライズは関数化
* API機能性
* サーバーのソースコードを短くに

ファイルの表示

@ -14,6 +14,7 @@ type Config struct {
linkpath string
webpath string
domain string
ip string
}
func geturl (url string, linkpath string, checkjson bool) (string, string) {
@ -75,6 +76,9 @@ func getconf () (Config, error) {
if payload["domain"] == nil {
return cnf, errors.New("「domain」の値が設置していません。")
}
if payload["ip"] == nil {
return cnf, errors.New("「ip」の値が設置していません。")
}
if _, err := os.Stat(payload["webpath"].(string)); err != nil {
fmt.Printf("%v\n", err)
return cnf, errors.New("mkdirコマンドを使って、 " + payload["webpath"].(string))
@ -84,6 +88,7 @@ func getconf () (Config, error) {
}
cnf.webpath = payload["webpath"].(string)
cnf.domain = payload["domain"].(string)
cnf.ip = payload["ip"].(string)
payload = nil
return cnf, nil

ファイルの表示

@ -1,4 +1,5 @@
{
"domain": "https://urlo.li",
"webpath": "/var/www/htdocs/urloli"
"webpath": "/var/www/htdocs/urloli",
"ip": "0.0.0.0"
}

ファイルの表示

@ -6,7 +6,7 @@ import (
"strconv"
)
var version = "2.1.0"
var version = "2.1.1"
func help () {
fmt.Println("使い方:");

18
srv.go
ファイルの表示

@ -6,6 +6,9 @@ import (
"net/http"
"encoding/json"
"strings"
"log"
"os"
"path/filepath"
)
type (
@ -32,7 +35,16 @@ type (
)
func serv (cnf Config, port int) {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
err = os.Chdir(dir)
if err != nil {
log.Fatal(err)
}
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(cnf.webpath + "/static"))))
ftmpl := []string{cnf.webpath + "/view/index.html", cnf.webpath + "/view/header.html", cnf.webpath + "/view/footer.html"}
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
@ -156,6 +168,6 @@ func serv (cnf Config, port int) {
data = nil
})
fmt.Println(fmt.Sprint("http://127.0.0.1:", port, " でサーバーを実行中。終了するには、CTRL+Cを押して下さい。"))
http.ListenAndServe(fmt.Sprint(":", port), nil)
fmt.Println(fmt.Sprint("http://" + cnf.ip + ":", port, " でサーバーを実行中。終了するには、CTRL+Cを押して下さい。"))
http.ListenAndServe(cnf.ip + ":9910", nil)
}