Skip to content

Instantly share code, notes, and snippets.

View mr-pascal's full-sized avatar

Pascal mr-pascal

View GitHub Profile
// Methods
(() => {
let a = 5;
let b = { a: 4 };
((c, d) => {
c = 4;
d.a = 5;
})(a, b);
@mr-pascal
mr-pascal / hello.go
Last active February 13, 2021 08:58
package main
import "fmt"
func main() {
// Print "Hello, World!" to the console
fmt.Println("Hello, World!")
}
module hello
go 1.15
##### Stage 1 #####
### Use golang:1.15 as base image for building the application
FROM golang:1.15 as builder
### Create new directly and set it as working directory
RUN mkdir -p /app
WORKDIR /app
### Copy Go application dependency files
@mr-pascal
mr-pascal / main.go
Last active February 16, 2021 05:24
package main
import "github.com/gofiber/fiber/v2" // <-- Import Fiber
func main() {
// Create new Fiber application
app := fiber.New()
// Create a route on the default path, only returning some string
app.Get("/", func(c *fiber.Ctx) error {
module medium_go_fiber_swagger
go 1.15
require (
github.com/andybalholm/brotli v1.0.1 // indirect
github.com/gofiber/fiber/v2 v2.5.0 // indirect
github.com/klauspost/compress v1.11.7 // indirect
github.com/valyala/fasthttp v1.20.0 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
@mr-pascal
mr-pascal / main.go
Last active February 16, 2021 05:28
package main
import (
// Import Fiber Swagger
"github.com/arsmn/fiber-swagger/v2"
// Import Go Fiber
"github.com/gofiber/fiber/v2"
// Side Effect import for auto-generated swagger documentation
_ "medium_go_fiber_swagger/docs"
)
func readCSVFile(filePath string) (persons []Person) {
isFirstRow := true
headerMap := make(map[string]int)
// Load a csv file.
f, _ := os.Open(filePath)
// Create a new reader.
r := csv.NewReader(f)
for {
func checkError(message string, err error) {
// Error Logging
if err != nil {
log.Fatal(message, err)
}
}
type Person struct {
Firstname string
Lastname string
func writeCSVFile(persons []Person, outputPath string) {
// Define header row
headerRow := []string{
"Firstname", "Lastname", "Country",
}
// Data array to write to CSV
data := [][]string{
headerRow,
}