Welcome to Ed2Ti Blog.

My journey on IT is here.

At Trebas (Computer Hardware & Software Environment), the challenger proposed by Ghazal G.Fard starts with a WebServer in GoLang.

Before commenting on the code, we need to understand two differences between python and GoLang.

1) To "ignore" a line in Python we use # and in Golang we use // Some other languages like C, use #, and others, like PHP, use // or /* */.

2) In python I don't need to define the main() function.

We need to keep in mind that we need to develop clean code. For example, is a good practice to use MVC (Model, View, Controller) techniques.

On the code, we need to import three packages: "fmt", "log", "net/http"

The fmt package we use to give a response. Can be on screen, or in this case, a web response. For the log package, we are just writing a log. The net/http we use to start a webserver.

There are a lot of concepts that we can present in the future.

//# *************************** #
//# College: Trebas Institute 
//# Professor: Ghazal G.Fard
//# Class: Edward
//# Day: 2022-06-21
//# *************************** #

package main
import (
    "fmt"
    "log"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){
        fmt.Fprintf(w, "Hello!")
    })


    fmt.Printf("Starting server at port 8080n")
    if err := http.ListenAndServe(":8080", nil); err != nil {
        log.Fatal(err)
    }
}

In this example, we do not use a concept of routes. Next week I'll start a new project to demonstrate rote on the GoLang web server.

Thank you for your time, and I hope that you can get an answer to your question.