Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
v1.1.0: Change error msg, Changes 2 files name to ticker.go...
Browse files Browse the repository at this point in the history
- Change error messages
- backend and update: changed files name to ticker.go
- Update README, Makefile
- Added nodemon
- website: URL type now is database.URL
- backend: Remove unused http info
- Upgrade deps
  • Loading branch information
Medzik authored and Medzik committed Jul 19, 2021
1 parent e5bb069 commit bd660f5
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 58 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

# Output binary
*.out
/pingbot*
dist/

# Sums
MD5SUM
SHA256SUM

VERSION
dist/
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ build:
run:
go run .

deps:
go get -v

clean:
go clean
rm pingbot* dist/
rm -rf pingbot* dist/
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Pingbot - Backend

![Pipeline Badge](https://gitlab.com/gaming0skar123/go/pingbot/badges/main/pipeline.svg)

## Install Pre-Compile binary

* Linux
* Downoad `curl -L https://gitlab.com/gaming0skar123/go/pingbot/-/jobs/artifacts/main/raw/pingbot-linux-amd64?job=build --output pingbot`
* Add permissions `chmod +rwx pingbot`
* Run binary `./pingbot`
* Linux amd64
* [Download](https://github.com/MedzikUser/go-pingbot/releases) latest version
* Unpack file `tar xzf pingbot_{VERSION}_linux_amd64.tar.gz`
* Create an .env and config.yml file and complete according to .env.schema and config.schema.yml
* Add permissions `chmod +rwx pingbot.out`
* Run binary `./pingbot.out`

## Disable Automatic Updates

Expand Down
6 changes: 0 additions & 6 deletions backend/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package backend
import (
"net/http"

"github.com/tcnksm/go-httpstat"
"gitlab.com/gaming0skar123/go/pingbot/common"
"gitlab.com/gaming0skar123/go/pingbot/database"
)
Expand Down Expand Up @@ -31,11 +30,6 @@ func loop(value database.URL) {
return
}

var result httpstat.Result

ctx := httpstat.WithHTTPStat(req.Context(), &result)
req = req.WithContext(ctx)

client := http.DefaultClient
r, err := client.Do(req)
if checkErr(err, "ping url") {
Expand Down
3 changes: 2 additions & 1 deletion backend/start.go → backend/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"gitlab.com/gaming0skar123/go/pingbot/config"
)

func Start() {
func Ticker() {
// Ping on Start
ping()

Expand All @@ -20,6 +20,7 @@ func Start() {
ping()
case <-quit:
ticker.Stop()

return
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package config

var Version = "1.0.1"
var Version = "1.1.0"
10 changes: 6 additions & 4 deletions database/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package database

import (
"context"
"os"
"time"

"gitlab.com/gaming0skar123/go/pingbot/common"
"gitlab.com/gaming0skar123/go/pingbot/config"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand All @@ -18,13 +20,13 @@ func Connect() {
defer cancel()

Client, err := mongo.Connect(ctx, options.Client().ApplyURI(config.Mongo_URI))
if err != nil {
panic("Failed Connecting to DB: " + err.Error())
if common.CheckErr(err, "failed connecting to db") {
os.Exit(1)
}

err = Client.Ping(ctx, readpref.Primary())
if err != nil {
panic("Failed Pinging DB: " + err.Error())
if common.CheckErr(err, "failed pinging db") {
os.Exit(1)
}

DB = Client.Database(config.Mongo_DB)
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/go-playground/validator/v10 v10.7.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/joho/godotenv v1.3.0
Expand All @@ -22,14 +23,16 @@ require (
github.com/posener/complete v1.2.3 // indirect
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/sirupsen/logrus v1.8.1
github.com/tcnksm/go-httpstat v0.2.0
github.com/ugorji/go v1.2.6 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
go.mongodb.org/mongo-driver v1.6.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20210716203947-853a461950ff // indirect
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
340 changes: 332 additions & 8 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
opts.Parse(&cmd)

if cmd.Update {
go update.Updater()
go update.Ticker()
} else {
log.Warn("Auto Update -> Disabled")
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func main() {
database.Connect()

go website.Server()
backend.Start()
backend.Ticker()
}
7 changes: 7 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"watch": ["*"],
"ext": "go json",
"signal": "SIGTERM",
"quiet": true,
"exec": "clear && go build -o pingbot.out || exit 1 && ./pingbot.out"
}
2 changes: 1 addition & 1 deletion update/updater.go → update/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"gitlab.com/gaming0skar123/go/pingbot/config"
)

func Updater() {
func Ticker() {
// Check on start
Update()

Expand Down
15 changes: 3 additions & 12 deletions website/routes/api/getAll.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"encoding/base64"
"fmt"
"net/http"

Expand Down Expand Up @@ -33,14 +32,11 @@ func GetAll(c *gin.Context) {
return
}

var db []dbType
var db []database.URL

for _, value := range results {
hash := base64.URLEncoding.EncodeToString([]byte(value.URL))

db = append(db, dbType{
URL: value.URL,
Hash: hash,
db = append(db, database.URL{
URL: value.URL,
})
}

Expand All @@ -49,8 +45,3 @@ func GetAll(c *gin.Context) {
"db": db,
})
}

type dbType struct {
URL string
Hash string
}
2 changes: 1 addition & 1 deletion website/routes/api/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func Insert(c *gin.Context) {
var post URLType
var post database.URL
err := c.BindJSON(&post)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
Expand Down
5 changes: 0 additions & 5 deletions website/routes/api/type.go

This file was deleted.

4 changes: 3 additions & 1 deletion website/routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ import (
)

func Index(c *gin.Context) {
c.String(http.StatusOK, "Ready!")
c.JSON(http.StatusOK, gin.H{
"success": true,
})
}
7 changes: 5 additions & 2 deletions website/server.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package website

import (
"os"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"gitlab.com/gaming0skar123/go/pingbot/common"
"gitlab.com/gaming0skar123/go/pingbot/config"
"gitlab.com/gaming0skar123/go/pingbot/website/routes"
"gitlab.com/gaming0skar123/go/pingbot/website/routes/api"
Expand All @@ -24,7 +27,7 @@ func Server() {
api.ApplyRoutes(router)

err := router.Run(config.Port)
if err != nil {
panic("Starting GIN Server: " + err.Error())
if common.CheckErr(err, "gin start") {
os.Exit(1)
}
}

0 comments on commit bd660f5

Please sign in to comment.