Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #3

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mongodb_uri = "mongodb://localhost:27017"
mongodb_name = "SC_Links"
base_url = "http://localhost:8080"
host = "0.0.0.0"
port = "8080"
jwt_secret_key = "_)8j1*91'?8Xj/U,c+1jeWdjZS%E}H"
allowed_github_org = "Faner201"
telegram_contact_username = "Faner201"
github_client_id = "feff6861dc4060bf47d5"
github_client_secret = "348f3c8fd1d5c73f12ce6b1d609f489aae56ceb9"
70 changes: 68 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
package main

import "fmt"
import (
"context"
"errors"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"

"github.com/Faner201/sc_links/internal/auth"
"github.com/Faner201/sc_links/internal/config"
"github.com/Faner201/sc_links/internal/db"
"github.com/Faner201/sc_links/internal/github"
"github.com/Faner201/sc_links/internal/server"
"github.com/Faner201/sc_links/internal/shorten"
"github.com/Faner201/sc_links/internal/storage/shortening"
"github.com/Faner201/sc_links/internal/storage/user"
)

func main() {
fmt.Print("Alloxa")
dbCtx, dbCancel := context.WithTimeout(context.Background(), 1*time.Second)
defer dbCancel()

config.Init()

Check failure on line 27 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `config.Init` is not checked (errcheck)

mgoClient, err := db.Connect(dbCtx, config.Get().DB.URI)
if err != nil {
log.Fatal(err)
}

mgoDB := mgoClient.Client().Database(config.Get().DB.Database)

var (
shorteningStorage = shortening.NewMongoDB(mgoDB)
userStorage = user.NewMongoDB(mgoDB)
shortener = shorten.NewService(shorteningStorage)
githubClient = github.NewClien()
authenticator = auth.NewService(
githubClient,
userStorage,
config.Get().Github.ClientID,
config.Get().Github.ClientSecret,
)
srv = server.New(shortener, authenticator)
)

srv.AddCloser(mgoClient.Close)

quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)

go func() {
if err := http.ListenAndServe(config.Get().ListenAddr(), srv); !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("error running server: %v", err)
}
}()

log.Println("server started")
<-quit

shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer shutdownCancel()

if err := srv.Shutdown(shutdownCtx); err != nil {
log.Fatalf("error closing server: %v", err)
}

log.Println("server stopped")

}
38 changes: 32 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
module github.com/Faner201/sc_links

go 1.20
go 1.19

require (
github.com/brianvoe/gofakeit/v6 v6.21.0 // indirect
github.com/cweill/gotests v1.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-github/v48 v48.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/samber/mo v1.8.0 // indirect
github.com/sethvargo/go-envconfig v0.9.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.11.2 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/oauth2 v0.9.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading