Skip to content

Instantly share code, notes, and snippets.

View BrianMwas's full-sized avatar
🎯
Make it happen

Brian Mwangi BrianMwas

🎯
Make it happen
View GitHub Profile
docker build -t gomongo:latest .
EXPOSE 4400
CMD ["/app/main"]
@BrianMwas
BrianMwas / dockerfile
Last active August 4, 2023 14:11
addition-docker file
FROM alpine:3.16
WORKDIR /app
COPY --from=builder /app/main .
EXPOSE 4400
CMD ["/app/main"]
FROM golang:1.19-alpine3.16 AS builder
WORKDIR /app
COPY . .
RUN go build -o main main.go
const (
MONGO_URI = "mongodb://%s:%s@mongo:%v/golangmongo?authSource=admin"
)
conn := fmt.Sprintf(MONGO_URI, "root", "rootpassword", 8081)
// Access the client
client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(connectionURI))
docker run --name mongo \
-p 8081:27017 \
-e MONGO_INITDB_ROOT_USERNAME=root \
-e MONGO_INITDB_ROOT_PASSWORD=rootpassword \
-d mongo:4
//How we will pas data between routes.
// We can pass the data through bindings or better yet through our navigation functions
Get.to(AppLinks.DASHBOARD, arguments: { "username": "John Doe" });
// Later in the dashboard controller accessing the arguments
final args = Get.arguments;
// Since the arguments are passed in as a map you can access the username using Map access functionalities that dart provides
final username = args["username"];
class FavoritesBinding extends Bindings {
@override
void dependencies() {
// Lazily inject the dependency and only use the dependency when needed.
Get.lazyPut(() => FavoritesController());
}
}
/*
***Other Code**
// Can be called within controllers
void toDashboard() {
Get.to(
AppLinks.DASHBOARD,
// Transition as a property. Different transitions can be applied. Such as
// fade,
// fadeIn,
// rightToLeft,
// leftToRight,
// upToDown,
// Other code
GetPage(
name: AppLinks.DASHBOARD,
page: () => Dashboard(),
middlewares: [
// Add here
AuthGuard(),
],
children: [
GetPage(