Giter VIP home page Giter VIP logo

golang-workshop's Introduction

Kompetensdag Umeå 2020-01: Golang!

Detta repo innehåller instruktioner och källkod för kompetensdagen om Golang.

Vi kommer att börja med en introduktion av språket och därefter jobba med ett övningsprojekt. Men innan vi börjar behöver man ha utfört samtliga steg av förberedelserna nedan.

Förberedelser

  • Installera Go för ditt OS (senaste versionen)

  • Bestäm var du vill lägga dina Go-projekt och sätt GOPATH

    Golang lägger all kod (även dina Git-repo), binärer, och andra paket i en enda katalog och den bestämmer man med GOPATH. Om man inte väljer något används <hemkatalog>/go, men om man t ex har en arbetskatalog <hemkatalog>/Workspace där man föredrar att lägga alla sina repon kan man ange <hemkatalog>/Workspace/go. Man kan om man vill lägga den i en katalog som inte heter go också, t ex /foo/bar.

  • Bekräfta att Go är korrekt konfigurerat genom följande:

    • Skapa katalogen <GOPATH>/src/hello
    • I den katalogen, lägg in följande i hello.go:
    package main
    
    import "fmt"
    
    func main() {
        fmt.Printf("hello, world\n")
    }
    • Kompilera programmet genom att gå till katalogen du skapat och köra go build
    • Notera att du bör ha fått en binär hello i samma katalog
    • Exekvera nu programmet genom att köra ./hello
  • Konfigurera valfri editor eller IDE. T ex:

    • VS Code med vscode-go
    • Atom med go-plus (och gärna go-debug)
    • Sublime med GoSublime (finns också sublime-build)
    • Eclipse med GoClipse
    • Vim med vim-go
    • Jetbrains GoLand (tyvärr endast betald)
    • Idea med Go plugin (endast tillgänglig i Ultimate)

Introduktion

Som introduktion till språket använder vi oss av The Little Go Book.

Se även Effective Go som är en utmärkt referens.

Övningsprojekt: en chat-klient

Detta projekt går ut på att vi skall bygga en klient till ett litet chat-system som har förberetts för kursen. Vi kommer att introducera den på plats, men nedan finns även lite nödvändig dokumentation.

Docs

This section describes how to integrate with the system

Name server

Holds an index of registered clients. Supported operations are currently: list clients, register client. When a client is registered it is instantly added to the index. I.e. after a client is added to the index it will instantly be present in the list of clients. Connected clients will have to continuously update their status. Every five seconds, the index is pruned and clients with a connected time > 5sec will be removed from the index. I.e. clients will have to periodically, with interval < 5sec, update their status again. A clients presence in the list is no guarantee that it will be possible to connect to it.


GET/clients

Lists the connected endpoints. The connected attribute determines the last time the client announced its present.

Example response:

{
    "82b5268c-8231-4563-9c26-be27ea7a7abe": {
        "ip": "192.1.1.1",
        "port": 1234,
        "connected": "2019-12-19T21:20:49.49786+01:00",
        "name": "linus"
    },
    "b79534f4-810b-454a-a52e-fd4b098dca7a": {
        "ip": "192.1.1.1",
        "port": 1234,
        "connected": "2019-12-19T21:21:02.306181+01:00",
        "name": "linus"
    }
}

POST/client

Registers a client to the index.

Example request body:

{
    "ip": "192.1.1.1",
    "port": 1234,
    "name": "linus"
}

Example response:

{
   "id": "f2ab3b6e-3284-49d4-b856-8e0939270566"
}

PATCH/client

Tells the name server that this client is still connected and updates the connected timestamp.

Example request:

{
    "id": "fc72368b-1f51-455b-81fc-0421fdf8666a"
}

Example response:

{
    "82b5268c-8231-4563-9c26-be27ea7a7abe": {
        "ip": "192.1.1.1",
        "port": 1234,
        "connected": "2019-12-19T21:20:49.49786+01:00",
        "name": "linus"
    },
    "b79534f4-810b-454a-a52e-fd4b098dca7a": {
        "ip": "192.1.1.1",
        "port": 1234,
        "connected": "2019-12-19T21:23:02.306181+01:00",
        "name": "linus"
    }
}

golang-workshop's People

Contributors

linuslagerhjelm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.