Skip to content

V for Go developers

Alexander Medvednikov edited this page Nov 3, 2019 · 11 revisions
Hello World
package main
import "fmt"
func main() {
  fmt.Println("Hello World!")
}
fn main() {
  println('Hello World!')
}
Slice initialization
numbers := []int{1, 2, 3, 4};
numbers := [1, 2, 3, 4]
Add an element to a slice
numbers = append(numbers, 5)
numbers << 5
Printing a slice
fmt.Println(numbers)
println(numbers)
Filtering a vector
even := make([]int, 0)
for _, num := range numbers {
  if num % 2 == 0 {
    even = append(even, num)
  }
}
even := numbers.filter(it % 2 == 0)
Reading a file
import (
    "io/ioutil"
    "log"
)
b, err := ioutil.ReadFile(path)
if err != nil {
        log.Println(err)
}
text := string(b)
import os
text := os.read_file(path)or{
  eprintln(err)
}