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

Commit

Permalink
Merge pull request #5 from CastyLab/develop
Browse files Browse the repository at this point in the history
Loading database, oauth and jwt configurations in main file
  • Loading branch information
mrjosh committed Sep 9, 2020
2 parents 523b0e2 + a1d7313 commit 25dd8f8
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 334 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ RUN mkdir /code
# Adding project to work directory
ADD . /code

RUN mkdir /config

# Removing old JWT keys
RUN rm -rf /code/config/jwt.key\
/code/config/jwt.pub
RUN rm -rf /config/jwt.key /config/jwt.pub

# Generate jwt keys
RUN cd /code/config && ssh-keygen -t rsa -N '' -b 4096 -m PEM -f jwt.key &&\
RUN cd /config && ssh-keygen -t rsa -N '' -b 4096 -m PEM -f jwt.key &&\
openssl rsa -in jwt.key -pubout -outform PEM -out jwt.pub;

# Choosing work directory
Expand All @@ -33,4 +34,5 @@ RUN go build -o casty.gRPC.server .

EXPOSE 55283

CMD ["./casty.gRPC.server", "-port", "55283"]
ENTRYPOINT ["./casty.gRPC.server"]
CMD ["--port", "55283"]
14 changes: 6 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"flag"
"fmt"
"gopkg.in/yaml.v2"
"log"
Expand Down Expand Up @@ -44,17 +43,16 @@ type ConfMap struct {
StoragePath string `yaml:"storage_path"`
}

var Map *ConfMap
var Map = new(ConfMap)

func init() {
configFileName := flag.String("config-file", "config.yml", "config.yaml file")
flag.Parse()
file, err := os.Open(*configFileName)
func Load(filename string) error {
file, err := os.Open(filename)
if err != nil {
log.Fatal(fmt.Sprintf("could not open config.yml file : %v", err))
return fmt.Errorf("could not open config file: %v", err)
}
if err := yaml.NewDecoder(file).Decode(&Map); err != nil {
log.Fatal(fmt.Sprintf("could not decode config file : %v", err))
return fmt.Errorf("could not decode config file: %v", err)
}
log.Printf("ConfigMap Loaded: [version: %s]", Map.App.Version)
return nil
}
8 changes: 4 additions & 4 deletions db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"github.com/CastyLab/grpc.server/config"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"time"
)

var (
Connection *mongo.Database
)

func init() {
func Configure() error {

ctx, _ := context.WithTimeout(context.Background(), 20 * time.Second)

Expand All @@ -28,12 +27,13 @@ func init() {

client, err := mongo.NewClient(opts)
if err != nil {
log.Fatal(err)
return fmt.Errorf("could not create new mongodb client: %v", err)
}

if err := client.Connect(ctx); err != nil {
log.Fatal(err)
return fmt.Errorf("could not connect to mongodb client: %v", err)
}

Connection = client.Database(config.Map.Secrets.Db.Name)
return nil
}
43 changes: 0 additions & 43 deletions internal/internal.go

This file was deleted.

74 changes: 0 additions & 74 deletions internal/services/theater/update.go

This file was deleted.

117 changes: 0 additions & 117 deletions internal/services/user/user.go

This file was deleted.

Loading

0 comments on commit 25dd8f8

Please sign in to comment.