diff --git a/slides/go/commands.md b/slides/go/commands.md new file mode 100644 index 0000000..c5e5044 --- /dev/null +++ b/slides/go/commands.md @@ -0,0 +1,40 @@ +## init + +```sh +go mod tidy +go mod init hello +``` + +## Build + +```sh +go build . +go tool dist list ## list arch +``` + + +## Types + +int32,ing64, +int -> depends on arch +rune -> utf char +string -> array of runes + + +### Other + +```sh +ldd ./hello +ls -lah +strip hello +``` + +[online compiler](https://godbolt.org) + + +### Notes + + - standard lib is huge + + - [beginer go](https://gobyexample.com/) + - [advanced go](https://go.dev/ref/spec) diff --git a/slides/go/go.mod b/slides/go/go.mod new file mode 100644 index 0000000..a812472 --- /dev/null +++ b/slides/go/go.mod @@ -0,0 +1,5 @@ +module hello + +go 1.24.3 + +require github.com/radovskyb/watcher v1.0.7 // indirect diff --git a/slides/go/hello b/slides/go/hello new file mode 100755 index 0000000..af2e57c Binary files /dev/null and b/slides/go/hello differ diff --git a/slides/go/main.go b/slides/go/main.go new file mode 100644 index 0000000..5c03b85 --- /dev/null +++ b/slides/go/main.go @@ -0,0 +1,62 @@ +package main + +import ( + "net/http" +) + + +type Point struct { + x int + y int +} + + type Boja int + + const ( + plava = iota //asc + zuta + crvena + ) + + const ( + plava = iota << 1 + zuta // 010 + crvena // 100 + ) + + type Vektor2d struct { + x int + y int + } + + type Vektor3d struct { + x ,y, z int + } + + type(p Point) D + + + type Vektor interface { + Duzina() float32 + } + + +func main() { + + p:= Vektor2d[ + x:1, + y:1 + ] + +fmt.Println(p.) + // web server + + http.HandleFunc("/", a ) + http.ListenAndServe(":8080", nil) + +} + +func a(w http.ResponseWriter, r *http.Request){ + w.Write([]byte("Hello Web")) +} + diff --git a/slides/go/main1.go b/slides/go/main1.go new file mode 100644 index 0000000..a7024d6 --- /dev/null +++ b/slides/go/main1.go @@ -0,0 +1,45 @@ +//go:build exclude +package main + +import "fmt" + +func main() { + + var a int + var s string = "hello world " + "!!!" + + var c = 5 + + a = a + 1 + + b := 1 + b := []byte(a) + c := string(b) + + _ = b + _ = c + + fmt.Println("Hello Wordl", "qwe") + fmt.Println(s) + + { + d = d + } + + d := 5 + f(d) + fmt.Println(a, "1") + + + // std lib + a : = []byte{1,2,3,4} + fmt.Println(hex.EncodeToString(a)) + + crypto.MD5.New() + +} + + +func f(str *int) { + a=1 +} diff --git a/slides/go/server.go b/slides/go/server.go new file mode 100644 index 0000000..bb21b7d --- /dev/null +++ b/slides/go/server.go @@ -0,0 +1,20 @@ +//go:build exclude +package main + +import ( + "net/http" +) + +func main() { + + // web server + + http.HandleFunc("/", a ) + http.ListenAndServe(":8080", nil) + +} + +func a(w http.ResponseWriter, r *http.Request){ + w.Write([]byte("Hello Web")) +} + diff --git a/slides/go/webgo/dmz b/slides/go/webgo/dmz new file mode 100755 index 0000000..0b0a68a Binary files /dev/null and b/slides/go/webgo/dmz differ diff --git a/slides/go/webgo/go.mod b/slides/go/webgo/go.mod new file mode 100644 index 0000000..ac9eb6b --- /dev/null +++ b/slides/go/webgo/go.mod @@ -0,0 +1,3 @@ +module dmz + +go 1.25.1 diff --git a/slides/go/webgo/main.go b/slides/go/webgo/main.go new file mode 100644 index 0000000..3b0bff6 --- /dev/null +++ b/slides/go/webgo/main.go @@ -0,0 +1,100 @@ +package main + +import ( + "encoding/json" + "html/template" + "fmt" + "net/http" + // "github.com/radovskyb/watcher" +) + +func main(){ + // w := watcher.New() + port := ":8080" + http.HandleFunc("/{$}", HtmlContentMiddleware(HomeHandler)) + http.HandleFunc("/about", HtmlContentMiddleware(AboutHandler)) + http.HandleFunc("GET /api", HtmlContentMiddleware(ApiHandler)) + http.HandleFunc("POST /api", HtmlContentMiddleware(ApiHandler)) + http.HandleFunc("/", NotFoundHandler) + + fmt.Println("http://localhost"+port) + http.ListenAndServe(port, nil) +} + +type handleFunc func(w http.ResponseWriter, r *http.Request) + +func HtmlContentMiddleware(f handleFunc) handleFunc { + return func(w http.ResponseWriter, r *http.Request){ + w.Header().Add("Content-Type", "text/html") + f(w,r) + } +} + + +func HomeHandler(w http.ResponseWriter, r *http.Request){ + + // data := struct{ + // Name string + // }{ + // Name: "Coja", + // } + + temp := template.New("home") + temp.Parse(baseTemplate) + temp.Execute(w,messages) + + // home := "Hello world" + // w.Header().Add("Content-Type", "text/html") + + w.Write(temp) +} + +func AboutHandler(w http.ResponseWriter, r *http.Request){ + // w.Header().Add("Content-Type", "text/html") + w.Write([]byte("about")) +} + +func NotFoundHandler(w http.ResponseWriter, r *http.Request){ + // w.Header().Add("Content-Type", "text/html") + w.WriteHeader(http.StatusNotFound) + w.Write([]byte("404 Not Found")) +} + +func ApiHandler(w http.ResponseWriter, r *http.Request){ + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusNotFound) + // w.Write([]byte("[1,2,3]")) + var filteredMessages []Message + userParam := r.URL.Query().Get("user") + + if userParam != ""{ + for _ ,m:=range messages { + if userParam == m.User{ + filteredMessages = append(filteredMessages, m) + } + } + } else{ + filteredMessages = messages + } + json.NewEncoder(w).Encode(filteredMessages) +} + +func NewMessageHandler(w http.ResponseWriter, r *http.Request){ + + var message Message + + err := json.NewDecoder(r.Body).Decode(&message) + userParam := r.URL.Query().Get("user") + + if err != nil{ + w.WriteHeader(http.StatusBadRequest) + return + } + + if userParam != ""{ + w.WriteHeader(http.StatusBadRequest) + return + } + + // messages.append(messages, message) +} diff --git a/slides/go/webgo/message.go b/slides/go/webgo/message.go new file mode 100644 index 0000000..4bc5968 --- /dev/null +++ b/slides/go/webgo/message.go @@ -0,0 +1,25 @@ +package main + +type Message struct { + Content string + User string +} + +var messages []Message = []Message { + { + Content: "hi", + User: "dmz", + }, + { + Content: "hello", + User: "admin", + }, + { + Content: "sup?", + User: "dmz", + }, + { + Content: "s3nd nud3s", + User: "admin", + }, +} diff --git a/slides/go/webgo/template.go b/slides/go/webgo/template.go new file mode 100644 index 0000000..0f41c65 --- /dev/null +++ b/slides/go/webgo/template.go @@ -0,0 +1,20 @@ +package main + +var baseTemplate =` + + + Home +