Entries tagged “#Go”

Mon 16 January 2017

Golang接口型函数

package main import ( "fmt" ) type Handler interface { Do(k, v interface{}) } type HandlerFunc func(k, v interface{}) func (f HandlerFunc) Do(k, v interface{}) { f(k, v) } func Each(m map[interface{}]interface{}, h Handler) { for k, v := range m { h.Do(k, v) } } func EachFunc(m map[interface{}]interface ... read more
Tue 10 May 2016

Golang编程练习

完整代码 戳这里 1. 验证给定字符串是否为合法身份证号码 算法:前17位纯数字分别乘以相应的因子,然后求和后除以11取余数。使用该余数取得校验字节数组中相位位置的字节与身份证最后一位字节做比较。如果相等即为合法身份证! package main import "fmt" import "strconv" var ( Factories [17]int = [17]int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2} ValidateBits []byte = []byte("10X98765432") ) func IsValidIDCode(id string) bool { idBytes := []byte(id ... read more
 

Tags