initial commit
This commit is contained in:
84
app.go
Normal file
84
app.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-yaml/yaml"
|
||||
"os"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
General GeneralConfig `yaml:"general"`
|
||||
Sites []SiteConfig `yaml:"sites"`
|
||||
}
|
||||
|
||||
type GeneralConfig struct {
|
||||
CacheTime int `yaml:"cachetime"`
|
||||
DBType string `yaml:"dbtype"`
|
||||
SQLAddr string `yaml:"sqladdr"`
|
||||
}
|
||||
|
||||
type SiteConfig struct {
|
||||
Name string `yaml:"name"`
|
||||
URL string `yaml:"url"`
|
||||
Type string `yaml:"type"`
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
func main() {
|
||||
// YAMLファイルを読み込む
|
||||
data, err := os.Open("config.yaml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer data.Close()
|
||||
err = yaml.Unmarshal(data, &config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
r := gin.Default()
|
||||
r.GET("/api/getStatus", func(c *gin.Context) {
|
||||
// 全てのサイトのステータス情報をJSON形式で返す
|
||||
|
||||
})
|
||||
r.GET("/api/getStatus/:URL", func(c *gin.Context) {
|
||||
// 指定したサイトのステータス情報をJSON形式で返す
|
||||
url := c.Param("URL")
|
||||
|
||||
})
|
||||
r.Run(":8080")
|
||||
}
|
||||
|
||||
func initdb(){
|
||||
if config.General.DBType == "sqlite"{
|
||||
db, err := sql.Open("sqlite3", config.General.SQLAddr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer db.Close()
|
||||
// テーブルの作成
|
||||
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS sites (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
lastChecked DATETIME NOT NULL,
|
||||
lastDowned DATETIME NOT NULL,
|
||||
status TEXT NOT NULL
|
||||
)`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getstatus(url string) string {
|
||||
if url == "" {
|
||||
// 全てのWebサイトをチェックする
|
||||
} else{
|
||||
// 指定したWebサイトのみをチェックする
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user