80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
/*
|
|
Copyright Ghink Network Studio
|
|
Website: https://www.ghink.net
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
"io"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"vars"
|
|
"page/service"
|
|
"tools/loger"
|
|
)
|
|
|
|
func databaseService() {
|
|
for {
|
|
defer recover()
|
|
file,err:=os.OpenFile(vars.WorkPath+"/database.db",os.O_RDONLY,0600)
|
|
defer file.Close()
|
|
if err != nil {
|
|
continue
|
|
}
|
|
bytes,err:=ioutil.ReadAll(file)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
err=json.Unmarshal(bytes,&vars.Database)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
time.Sleep(time.Duration(10)*time.Second)
|
|
}
|
|
}
|
|
func nodeService() {
|
|
|
|
}
|
|
func syncService() {
|
|
for {
|
|
}
|
|
}
|
|
func hashFile(path string) string {
|
|
file,err:=os.Open(path)
|
|
defer file.Close()
|
|
if err != nil {
|
|
loger.LogIn("[Hash Thread]","Failed to calc hash of the file ",path,"! Error info: ",err.Error())
|
|
}
|
|
hash:=sha256.New()
|
|
if _,err := io.Copy(hash,file); err != nil {
|
|
loger.LogIn("[Hash Thread]","Failed to calc hash of the file ",path,"! Error info: ",err.Error())
|
|
}
|
|
sum:=hash.Sum(nil)
|
|
return hex.EncodeToString(sum)
|
|
}
|
|
func main() {
|
|
http.HandleFunc("/", service.PageService)
|
|
go http.ListenAndServe(":8000", nil)
|
|
go syncService()
|
|
go databaseService()
|
|
/*
|
|
go nodeService()
|
|
go consoleService()
|
|
*/
|
|
for {
|
|
|
|
}
|
|
}
|
|
/*
|
|
10001 Unspported choice for requests loading
|
|
10002 Directory listing is not allowed
|
|
10003 Cannot find file
|
|
10004 The file exists but cannot be read
|
|
10005 Please offer more params
|
|
*/ |