Last active
May 16, 2017 07:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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