Rock, Paper, Scissors

https://crossnative.github.io/cloudland-rps/

What's
cloud-native?

There is no cloud.
It's just someone else's computers.

Cloud native Technologies
empower to build and run
scalable applications
in modern, dynamic environments.Cloud Native Computing Foundation

The 12-Factor-App and Beyond

  1. One Codebase, One App
  2. API First
  3. Dependency Management
  4. Design, Build, Release, Run
  5. Configuration, Credentials and Code
  6. Logs
  7. Disposability
  1. Backing Services
  2. Environment Parity
  3. Administrative Processes
  4. Port Binding
  5. Stateless Processes
  6. Concurrency
  7. Telemetry
  8. Authentication and Authorization

Getting Started

Project Overview

Player vs. Computer API Calls

>_ Demo

Split into Session

Go Session

Prerequisites Go Session

Go

  • Go Compiler
  • optional: air for hot reload
    go install github.com/cosmtrek/air@latest

Frontend

First Steps in Go

  1. Get up and running
  2. Complete REST API
  3. Make Cloud Native or add your Features

Go Cloud Native Path

Cheatsheet Middleware for Logging and Recovery

Using middlewares from chi router or others.

                  r := chi.NewRouter()
                  r.Use(middleware.Logger)
                  r.Use(middleware.Recoverer)
                
  • What does the recovery middleware do?
  • Bonus: How can you set a request timeout using middleware?

Cheatsheet Configure Port
from Environment Variable

Using the Standard Library

                  func main() {
                    http.ListenAndServe(fmt.Sprintf(":%v", os.Getenv("PORT")), r)
                  }
                

Using envconfig

github.com/kelseyhightower/envconfig

                  // Application Configuration
                  type Config struct {
                    Port string `envconfig:"PORT" default:"8080"`
                  }
                  
                  func main() {
                    http.ListenAndServe(fmt.Sprintf(":%v", c.Port), r)
                  }     
                

Cheatsheet Handle Errors properly

Using the Standard Library


                  if err != nil {
                    http.Error(w, "Oops, that went wrong!", http.StatusInternalServerError)
                    return
                  }
                

Using Problem for HTTP APIs

Use rfc7807 with schneider.vip/problem

                  if err != nil {
                    problem.New(
                    problem.Wrap(err), 
                    problem.Status(http.StatusInternalServerError)
                    ).WriteTo(w)
                    return
                  }        

Cheatsheet Run in Container


                    # 1. RPS Builder
                    FROM golang as builder
                    WORKDIR /app
                    ADD . /app
                    RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o build/rps .
                    
                    # 2. RPS Container
                    FROM gcr.io/distroless/static
                    COPY --from=builder /app/build/rps /usr/bin/
                    EXPOSE 8080
                    ENTRYPOINT ["/usr/bin/rps"]
                  

Cheatsheet Add a Health Check

See github.com/hellofresh/health-go/v5.

                    // Register Health Check
                    h, _ := health.New(health.WithChecks(
                    health.Config{
                      Name:      "db",
                      Timeout:   time.Second * 2,
                      SkipOnErr: false,
                      Check: healthPgx.New(healthPgx.Config{
                        DSN: config.Db,
                      }),
                    },
                    ))
                    
                    // Register Health Check Handler Function
                    r.Get("/health", h.HandlerFunc)
                  

Cheatsheet Use PostgreSQL for Storage

Cheatsheet Cloud Deployment

Example Deployment for render

                    services:
                    - type: web
                    name: backend-go
                    env: go
                    plan: free
                    rootDir: backend-go
                    buildCommand: go build -o rps .
                    startCommand: ./rps
                  

Cheatsheet OpenTelemetry

Use otelchi

Spring Session

Prerequisites Spring Session

Frontend

First Steps Spring Session

  1. Run local Frontend together with example backend
    https://backend-spring.onrender.com/api/v1
  2. Build and Run Spring Backend
  3. Implement REST API
  4. Make Cloud Native or add further Features

Spring Cloud Native Path

Cheatsheet Error Handling

Cheatsheet Run in Container

With Buildpacks run
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=myorg/myapp

Feature Ideas Rock, Paper, Scissors

Interesting Links