Skip to content

Instantly share code, notes, and snippets.

@lengocgiang
Last active May 16, 2017 07:55
Show Gist options
  • Save lengocgiang/eadc80fccf2f4877f46f3dca167103f2 to your computer and use it in GitHub Desktop.
Save lengocgiang/eadc80fccf2f4877f46f3dca167103f2 to your computer and use it in GitHub Desktop.
I wrote a few mini functions to convert and support with go lang
package main
import (
"fmt"
"reflect"
)
func main() {
checkType()
}
func checkType() {
// Using "reflect" function to check type
var x = "this's string"
var y = 12345
if reflect.TypeOf(x).Kind() == reflect.String {
fmt.Printf("%T: %v \n", x, x)
}
if reflect.TypeOf(y).Kind() == reflect.Int {
fmt.Printf("%T: %v \n", y, y)
}
}
func removeLastString(str string) string {
if len(str) > 0 && str != "" {
return str[:len(str)-1]
}
return str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment