Jump to content

How to learn Golang?

G1K777

Hello,

this question might seem bit stupid but I'm dead serious with it.

To write a simple "Hello World!" in Go is simpler than doing this in NodeJS (Because NodeJS has a trash setup).


 

package main

import "fmt"

func main(){
  fmt.Println("Hello World")
}

Very simple right?

Each Youtube video about Golang I've seen kind helps but not really. All you hear "do this, this is for that.." but not in the Docs nor in any Youtube video have they explained the basics.

I mean how do you write variables in other languages?
 

// JS
var varName = 5;
let varName = 5;
const varName = 5;

// or

var varName1 = 5,
    varName2 = 6,
    varName3 = 7; //etc. Works same with const and let.

With PHP it's also easy, $variableName and it's done.

 

But in Golang I saw no one explaining this:
 

something := 5 // <-- talking about this.
var otherSomething int = 5

Luck that there is something like w3schools, MDN that makes everything really easy but where the heck do I learn the fundamentals of Golang?


All I want to do, is getting a webhost working on my PC. That's all.
The issue is, my browser (chrome) is loading the index.html but how do I load the CSS and JS?

 

I'm siting since 35-40h (in total, sleeping and breakes not included) googling Golang, the whole time. I'm kinda pissed how you can tell, who wouldn't be? It took me 1 day to run NodeJS without using express and make my website run on it.

With Golang I'm sitting here and i know nothing, the docs don't give you a starting point at all. They teach me how to make a gowiki where the content is loaded from txt files ? Like you seruous, txt files?

 

This is what i have now and don't ask me how it works.

package main

import (
    "io/ioutil"
    "net/http"
)

type MyHandler struct {
    http.Handler
}

func (this *MyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
    path := "public/index.html" // + req.URL.Path
    data, err := ioutil.ReadFile(string(path))

    if err == nil {
        w.Write(data)
    } else {
        w.WriteHeader(404)
        w.Write([]byte("404 - " + http.StatusText(404)))
    }
}

func main() {
    http.Handle("/", new(MyHandler))
    http.ListenAndServe(":3000", nil)
}

I never coded anything in Python, Delphi, any C language.

AMD FX8320 | GTX660 | 4x4GB DDR3 | LG ZR2740W

Logitech Wireless Pro  | Logitech G413 | Nuforce uDAC5  | AKG K612

Link to comment
Share on other sites

Link to post
Share on other sites

Perhaps https://github.com/a8m/go-lang-cheat-sheet

It's not much more than just a list of things, but does cover the fundamentals such as variables and the likes. Haven't worked in Golang myself though.

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×