Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
// UnaryClientInterceptor returns a new unary client interceptor that optionally logs the execution of external gRPC calls.
func UnaryClientInterceptor(logger *zap.Logger, opts ...Option) grpc.UnaryClientInterceptor {
o := evaluateClientOpt(opts)
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
fields := newClientLoggerFields(ctx, method)
startTime := time.Now()
err := invoker(ctx, method, req, reply, cc, opts...)
newCtx := ctxzap.ToContext(ctx, logger.With(fields...))
logFinalClientLine(newCtx, o, startTime, err, "finished client unary call")
return err
@percybolmer
percybolmer / Dockerexample-0.1.Dockerfile
Last active September 18, 2021 05:56
An example DockerFile
FROM golang:1.5
LABEL maintainer="PercyBolmer@medium"
RUN mkdir /app
COPY main.go /app
WORKDIR /app
RUN go build -o helloer .
CMD [ "/app/helloer" ]
@percybolmer
percybolmer / Super simple Hello World.go
Last active September 18, 2021 05:57
An example hello world API
package main
import (
"fmt"
"net/http"
"os"
"log"
)
FROM golang:1.5
LABEL maintainer="PercyBolmer@medium"
#ARG is used during the Image build
ARG port=8080
# Assign Environment variabel PORT the value of port. The user running the container can then override this with the -e flag
ENV PORT=${port}
RUN mkdir /app
COPY main.go /app
@percybolmer
percybolmer / Docker-compose.yaml
Last active January 11, 2021 21:09
Example docker-compose.yaml used in Medium post
# This compose is for demonstration how to serve our custom image and a prebuilt image
version: "3.0"
#Services defines what containers to run
services:
#server is the name for our custom image, this can be anything and is used by other services to refer to this.
server:
#the image to run the container from
image: "learndocker:0.2"
# set environments
environment:
# We add as builder to name our build stage. This is needed so that our second build can refer to it
FROM golang:1.15 as builder
LABEL maintainer="PercyBolmer@medium"
#ARG is used during the Image build
ARG port=8080
# Assign Environment variabel PORT the value of port. The user running the container can then override this with the -e flag
ENV PORT=${port}
RUN mkdir /app
FROM golang:1.5
LABEL maintainer="PercyBolmer@medium"
#ARG is used during the Image build
ARG port=8080
# Assign Environment variabel PORT the value of port. The user running the container can then override this with the -e flag
ENV PORT=${port}
RUN mkdir /app
COPY main.go /app
package main
import (
"fmt"
)
type Human struct {
Name string
}
// This is our method receiver, the type Human receives the Hello method
package main
import (
"fmt"
"time"
"errors"
)
// DateError is a custom error that will fulfill the Error interface
type DateError struct {
Message string
package main
import (
"fmt"
"time"
"errors"
)
type DateError struct {
Message string