Skip to content

Latest commit

 

History

History
167 lines (92 loc) · 6.55 KB

README.md

File metadata and controls

167 lines (92 loc) · 6.55 KB

GoLang

Go handbook Download PDF

GoLang Courses:

Developed at Google and made open source in 2009

It's a multithread language

Designed to run on multiple cores and built to support concurrency

Concurrency in Go is cheap and easy

for performant applications

Docker, Vault, Cockroach is written in Go

GoLang projects: Hello world starter

Hello World Starter App

hellowithgo

gohelp

Go Quiz App

The problem:

  • The task is to build a super simple quiz with a few questions and a few alternatives for each question. With one correct answer per question.
  • Backend - Golang
  • Database - Just in-memory , so no database
  • REST API or gRPC
  • CLI that talks with the API, preferably using https://github.com/spf13/cobra ( as cli framework )
  • cobra-cli Readme

Installing Cobra

cobra-cli cobrainstall

Facing issues with init but go it to work and get the Go project to initialise and run running

Testing the application and running "Hello World!" helloworldtest

fmt package

Package fmt implements formatted I/O with functions analogous to C's printf and scanf. The format 'verbs' are derived from C's but are simpler.

io package

Package io provides basic interfaces to I/O primitives. Its primary job is to wrap existing implementations of such primitives, such as those in package os, into shared public interfaces that abstract the functionality, plus some other related primitives.

Because these interfaces and primitives wrap lower-level operations with various implementations, unless otherwise informed clients should not assume they are safe for parallel execution.

Being able to print in the terminal

print

Create HTTP Server | http://localhost:3333

http

template package

Package template (html/template) implements data-driven templates for generating HTML output safe against code injection. It provides the same interface as package text/template and should be used instead of text/template whenever the output is HTML.

controlstruc reference: Go Web Examples

Decoding a csv file in go

Trying to run the csv file but there's errors in how I put together the csv structure and questions. runningthecsvfile code reference

How to read a csv file

How to write a csv file

Common Format and MIME Type for Comma-Separated Values (CSV) Files

Running through the csv file: (Working csv values)

readingcsv

Looping through the 3 questons & creating a map with keys:

4 basic range loop (for-each) patterns

Scanner in Go

Take Input from the User in Golang
Scan function in Golang

The Problem

User stories/Use cases

  • User should be presented questions with a number of answers

  • User should be able to select just one answer per question

  • User should be able to answer all the questions and then post his/her answers and get back how many correct answers there had and be displayed to the user.

  • User should see how good he/she rated compared to others that have taken the quiz, "You scored higher than 60% of all quizzers"

I created a multiple choice quiz that has options between A->D (4 choices to choose from)

Only one right answer per question.

There are 6 quesions the program loops through but the user only sees 3 questions at a time.

When the quiz is completed the user will see their results with the answer.

And if the user has scored higher than 60%, the user will see the printed "You scored higher than 60% of all quizzers"

The user will be asked if they would like to retry the quiz or if they would like to exit the application.

Installing more packages init

installpip

Gorilla

Viper

Vault

inconshreveable

apt-get

Ubuntu

The working app:

Last Edit: September 2022