- license: changed from MIT to 0BSD
- database: added retry to connect
- api: modified status
- config: moved to files env and no-env
- other modified: nodemon.json, .gitignore
This commit is contained in:
Medzik 2021-07-24 09:50:17 +00:00
parent 13771d1394
commit f1921ff8b1
12 changed files with 53 additions and 52 deletions

12
.gitignore vendored
View File

@ -8,16 +8,8 @@
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output binary
*.out
dist/
# Sums
MD5SUM
SHA256SUM
VERSION
# Test binary, built with `go test -c`
*.test

27
LICENSE
View File

@ -1,21 +1,14 @@
MIT License
The BSD Zero Clause License (0BSD)
Copyright (c) 2021 Medzik
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

13
config/no-env.go Normal file
View File

@ -0,0 +1,13 @@
package config
import "time"
// backend
var PingBot_Ticker = 2 * time.Minute
// update
var GH_Repo = "MedzikUser/go-pingbot"
var Latest_Version_Check = 2 * time.Minute
// website
var Port = ":8080"

View File

@ -1,5 +0,0 @@
package config
import "time"
var PingBot_Ticker = 2 * time.Minute

View File

@ -1,8 +0,0 @@
package config
import (
"time"
)
var GH_Repo = "MedzikUser/go-pingbot"
var Latest_Version_Check = 2 * time.Minute

View File

@ -1,3 +1,3 @@
package config
var Version = "1.2.0"
var Version = "1.3.0"

View File

@ -1,3 +0,0 @@
package config
var Port = ":8080"

View File

@ -15,18 +15,32 @@ import (
var Client mongo.Client
var Coll *mongo.Collection
func Connect() {
func Connect(retry ...int8) {
if len(retry) == 0 {
retry = append(retry, 0)
}
if retry[0] == 2 {
os.Exit(1)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Client, err := mongo.Connect(ctx, options.Client().ApplyURI(config.Mongo_URI))
if common.CheckErr(err, "connect to db") {
os.Exit(1)
time.Sleep(2 * time.Second)
Connect(retry[0] + 1)
return
}
err = Client.Ping(ctx, readpref.Primary())
if common.CheckErr(err, "ping db") {
os.Exit(1)
time.Sleep(2 * time.Second)
Connect(retry[0] + 1)
return
}
Coll = Client.Database(config.Mongo_DB).Collection(config.Mongo_Collection)

View File

@ -7,7 +7,8 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)
func Insert(url *URL) (*mongo.InsertOneResult, error) {ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
func Insert(url *URL) (*mongo.InsertOneResult, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result, err := Coll.InsertOne(ctx, url)

View File

@ -3,5 +3,5 @@
"ext": "go json",
"signal": "SIGTERM",
"quiet": true,
"exec": "clear && go build -o pingbot.out || exit 1 && ./pingbot.out || exit 1"
"exec": "clear && go build -o pingbot.out || exit 1 && ./pingbot.out || echo \"[\\033[0;31mPROGRAM PANIC\\033[0m]\" || exit 1"
}

View File

@ -21,14 +21,14 @@ func Status(c *gin.Context) {
pid := os.Getpid()
c.JSON(http.StatusOK, json{
"success": true,
"ping": json{
"all": backend.AmountSuccess + backend.AmountErr,
"success": backend.AmountSuccess,
"err": backend.AmountErr,
},
"stats": json{
"sys": json{
"pid": pid,
"os": runtime.GOOS,
"mem": json{
"alloc": mb(m.Alloc),
"totalalloc": mb(m.TotalAlloc),
@ -38,9 +38,13 @@ func Status(c *gin.Context) {
"cpu": json{
"usage": cpu(pid),
"num": runtime.NumCPU(),
"arch": runtime.GOARCH,
},
},
"v": config.Version,
"v": json{
"go": runtime.Version(),
"release": config.Version,
},
})
}