Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Netflix has open sourced his container management system called Titus written in Go Lang. You can see documentation of it here:

- https://netflix.github.io/titus/

Source code and Docs:

- https://github.com/Netflix/titus

#container_orchestration #docker #container #golang #go #netflix #titus #aws
os.Rename in goLang?

Function signature:

func Rename(oldpath, newpath string) error


What Rename does?

Rename renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. If there is an error, it will be of type *LinkError.

#golang #go #os #rename #os_rename
As you may already know in Python you can format your string using format as below:

file_name = "/root/openvpn/{}.ovpn".format(my_file_name)
// Or
file_name = "/root/openvpn/%s.ovpn" % my_file_name



In golang you need to use Sprintf method of fmt package like follow:

var fileName = fmt.Sprintf("/root/openvpn/%s.ovpn", myFileName)


#python #golang #go #fmt #sprintf #format
environments in Golang:

To set a key/value pair, use os.Setenv. To get a value for a key, use os.Getenv. This will return an empty string if the key isn’t present in the environment.

Use os.Environ to list all key/value pairs in the environment. This returns a slice of strings in the form KEY=value. You can strings.Split them to get the key and value. Here we print all the keys:

package main

import (
"os"
"strings"
"fmt"
)

func main() {
os.Setenv("FOO", "1")
fmt.Println("FOO:", os.Getenv("FOO"))
fmt.Println("BAR:", os.Getenv("BAR"))

fmt.Println()
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
fmt.Println(pair[0])
}
}


#golang #go #env #environment #environment_variables #range #setenv #getenv #environ
If you want to implement "Python Capitalize" method in Go:

strings.Title(strings.ToLower("MYNAME")) // output: Myname


There is another method called ToTitle which is used for one character long (but to letters):

str := "dz"
fmt.Println(strings.ToTitle(str)) // output: Dz


#python #golang #go #ToLower #Title #strings #capitalize #ToTitle
Slices are far more efficient than Arrays in Go. Assigning one array to another copies all the elements while in Slice it refers to the underlying Array.

There are major differences between the ways arrays work in Go and C. In Go,

- Arrays are values. Assigning one array to another copies all the elements.
- In particular, if you pass an array to a function, it will receive a copy of the array, not a pointer to it.
- The size of an array is part of its type. The types [10]int and [20]int are distinct.

*NOTE:* The value property can be useful but also expensive; if you want C-like behavior and efficiency, you can pass a pointer to the array.

Read more about arrays and slices here:

- https://golang.org/doc/effective_go.html#arrays

#go #arrays #slices