摘要:        
gin内置验证器使用 func TopicUrl(f1 validator.FieldLevel) bool { return true //返回true表示验证成功 } func main(){ router:=gin.Default() if v, ok := binding.Validator.Engine().(*validator.Validate); ok ...    阅读全文
posted @ 2019-12-19 23:06
离地最远的星
阅读(3498)
评论(0)
推荐(1)
        
            
        
        
摘要:        
type TopicQuery struct { UserName string `form:"username" json:"username"` Page int `form:"page" json:"page" binding:"required"` //binding:required表示必须有这个参数,否则err := context.Bind(query)...    阅读全文
posted @ 2019-12-19 23:02
离地最远的星
阅读(243)
评论(0)
推荐(0)
        
            
        
        
摘要:        
work,工作模式 一个消息只能被一个消费者获取 工作模式就是simple模式多了几个消费者,其他一样来自为知笔记(Wiz)    阅读全文
posted @ 2019-12-19 23:01
离地最远的星
阅读(225)
评论(0)
推荐(0)
        
            
        
        
摘要:        
gorm会默认给struct名称设置小写,并且加上复数形式 tc := &src.TopicClass{} //用orm去建表时驼峰个是你会用下划线隔开,所有TopicClass对应表为topic_class db.First(tc,2) //只取topic_class查询结果第一条,后面的2是可选参数,加上表示取主键=2的数据集的第一条,结构体必须标注了主键才可以查询到结果,如下面clas...    阅读全文
posted @ 2019-12-19 23:01
离地最远的星
阅读(244)
评论(0)
推荐(0)
        
            
        
        
摘要:        
simple模式代码 package RabbitMQ import ( "fmt" "github.com/streadway/amqp" "log" ) const MQURL = "amqp://guest:guest@127.0.0.1:5672/imooc" //创建rabbitmq结构体实例 type RabbitMQ struct { conn...    阅读全文
posted @ 2019-12-19 22:59
离地最远的星
阅读(242)
评论(0)
推荐(0)
        
            
        
        
摘要:        
rabbitmq是面向消息的中间件,用于组件之间的解耦,主要体现在消息的发送者和消费者之间无强依赖关系 rabbitmq特点: 高可用 拓展性,多语言客户端,管理界面 使用场景:流量削峰,异步处理,应用解耦等 VirtualHost RabbitMq的VirtualHost(虚拟消息服务器),每个VirtualHost相当于一个相对独立的RabbitMQ服务器;每个VirtualHost之...    阅读全文
posted @ 2019-12-19 22:58
离地最远的星
阅读(171)
评论(0)
推荐(0)
        
            
        
        
摘要:        
Publish/Subscribe,订阅模式 消息被路由投递给多个队列,一个消息可以被多个消费者获取 订阅模式代码 package RabbitMQ import ( "fmt" "github.com/streadway/amqp" "log" ) const MQURL = "amqp://guest:guest@127.0.0.1:5672/imooc" ...    阅读全文
posted @ 2019-12-19 22:54
离地最远的星
阅读(171)
评论(0)
推荐(0)
        
            
        
        
摘要:        
routing,路由模式 一个消息被多个消费者获取,并且消息的目标队列可被生产者指定 package RabbitMQ import ( "fmt" "github.com/streadway/amqp" "log" ) const MQURL = "amqp://guest:guest@127.0.0.1:5672/imooc" //创建rabbitmq结构体实...    阅读全文
posted @ 2019-12-19 22:52
离地最远的星
阅读(192)
评论(0)
推荐(0)
        
            
        
        
摘要:        
Redis的五大数据类型 redis的五大数据类型是,String(字符串),Hash(哈希),List(列表),Set(集合),zset(sorted set: 有序集合) string字符串 string是redis最基本的类型,一个key对应一个value Str1 := "hello" St    阅读全文
posted @ 2019-12-19 22:51
离地最远的星
阅读(518)
评论(0)
推荐(0)
        
            
        
        
摘要:        
go操作redis package main import ( "fmt" "github.com/garyburd/redigo/redis" ) func main() { //连接到redis conn, err := redis.Dial("tcp", "localhost:6379") if err != nil { fmt.Println...    阅读全文
posted @ 2019-12-19 22:50
离地最远的星
阅读(291)
评论(0)
推荐(0)
        
            
        
        
摘要:        
package main import ( "fmt" "sort" ) type ServerSlice []Server type Server struct { Weight int } //只要实现了下面三个方法就可以传入sort方法使用 func (p ServerSlice) Len() int { return len(p) } fu...    阅读全文
posted @ 2019-12-19 22:49
离地最远的星
阅读(398)
评论(0)
推荐(0)
        
            
        
        
摘要:        
package util import ( "fmt" "hash/crc32" "math/rand" "sort" "time" ) type HttpServer struct { //目标server类 Host string Weight int CWeight int //当前权重 ...    阅读全文
posted @ 2019-12-19 22:48
离地最远的星
阅读(1106)
评论(0)
推荐(0)
        
            
        
        
摘要:        
package main import ( "log" "net/http" "net/http/httputil" "net/url" "os" "os/signal" "regexp" "反向代理/util" ) type ProxyHandler struct { } func (*ProxyHandler) ServeH...    阅读全文
posted @ 2019-12-19 22:47
离地最远的星
阅读(451)
评论(0)
推荐(0)
        
            
        
        
摘要:        
来自为知笔记(Wiz)    阅读全文
posted @ 2019-12-19 22:46
离地最远的星
阅读(212)
评论(0)
推荐(0)
        
            
        
        
摘要:        
package util import ( "fmt" "hash/crc32" "math/rand" "time" ) type HttpServer struct { //目标server类 Host string Weight int } func NewHttpServer(host string, weight int) *Ht...    阅读全文
posted @ 2019-12-19 22:45
离地最远的星
阅读(303)
评论(0)
推荐(0)
        
            
        
        
摘要:        
func (this *LoadBalance) RoundRobinByWeight3() *HttpServer { //平滑加权轮询 for _, s := range this.Servers { s.CWeight = s.CWeight + s.Weight } sort.Sort(this.Servers) max := this....    阅读全文
posted @ 2019-12-19 22:44
离地最远的星
阅读(213)
评论(0)
推荐(0)
        
            
        
        
摘要:        
来自为知笔记(Wiz)    阅读全文
posted @ 2019-12-19 22:43
离地最远的星
阅读(290)
评论(0)
推荐(0)
        
            
        
        
摘要:        
package util import ( "math/rand" "time" ) type HttpServer struct { //目标server类 Host string } func NewHttpServer(host string) *HttpServer { return &HttpServer{Host: host} } type Lo...    阅读全文
posted @ 2019-12-19 22:41
离地最远的星
阅读(249)
评论(0)
推荐(0)
        
            
        
        
摘要:        
Go实现 在头里设置WWW-Authenticate 返回401 func (webhandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { writer.Header().Set("WWW-Authenticate", `Basic realm="您必须输入用户名和密码"`) writer...    阅读全文
posted @ 2019-12-19 22:41
离地最远的星
阅读(182)
评论(0)
推荐(0)
        
            
        
        
摘要:        
package main import ( "io/ioutil" "log" "net/http" "os" "os/signal" ) type ProxyHandler struct { } func (*ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { d...    阅读全文
posted @ 2019-12-19 22:40
离地最远的星
阅读(122)
评论(0)
推荐(0)
        
 
                    
                     
                    
                 
                    
                
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号