import the fmt package with an alias in go

To import the fmt package with an alias in Go, you can use the following syntax:

main.go
import f "fmt"
15 chars
2 lines

This will import fmt package with alias f, and you can then use it as f.Print() instead of fmt.Print().

Here is an example:

main.go
package main

import f "fmt"

func main() {
    f.Print("Hello, World!")
}
75 chars
8 lines

Output:

main.go
Hello, World!
14 chars
2 lines

related categories

gistlibby LogSnag