ステータスコード取得関数を大まかに実装。
This commit is contained in:
32
app.go
32
app.go
@@ -1,12 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-yaml/yaml"
|
"github.com/go-yaml/yaml"
|
||||||
"os"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"database/sql"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -47,7 +49,14 @@ func main() {
|
|||||||
})
|
})
|
||||||
r.GET("/api/getStatus/:URL", func(c *gin.Context) {
|
r.GET("/api/getStatus/:URL", func(c *gin.Context) {
|
||||||
// 指定したサイトのステータス情報をJSON形式で返す
|
// 指定したサイトのステータス情報をJSON形式で返す
|
||||||
url := c.Param("URL")
|
url := c.Param("URL", 0)
|
||||||
|
status := getstatus(url)
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"url": url,
|
||||||
|
"status": status,
|
||||||
|
"checked_at": time.Now().Format("2006-01-02 15:04:05"),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
r.Run(":8080")
|
r.Run(":8080")
|
||||||
@@ -76,10 +85,17 @@ func initdb(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getstatus(url string) string {
|
func getstatus(url string) (int) {
|
||||||
if url == "" {
|
//TODO: 鯖落ち検知時の返り値
|
||||||
// 全てのWebサイトをチェックする
|
r ,err := http.Head(url)
|
||||||
} else{
|
if err != nil {
|
||||||
// 指定したWebサイトのみをチェックする
|
return -1
|
||||||
}
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
return r.StatusCode
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func getstatusAll(url string) (string, string){
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user