github.com/cnotch/ipchub@v1.1.0/provider/route/route.go (about) 1 // Copyright (c) 2019,CAOHONGJU All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package route 6 7 import ( 8 "net/url" 9 10 "github.com/cnotch/ipchub/utils" 11 ) 12 13 // Route 路由 14 type Route struct { 15 Pattern string `json:"pattern"` // 路由模式字串 16 URL string `json:"url"` // 目标url 17 KeepAlive bool `json:"keepalive,omitempty"` // 是否一直保持连接,直到对方断开;默认 false,会在没有人使用时关闭 18 } 19 20 func (r *Route) init() error { 21 r.Pattern = utils.CanonicalPath(r.Pattern) 22 _, err := url.Parse(r.URL) 23 if err != nil { 24 return err 25 } 26 return nil 27 } 28 29 // CopyFrom 从源拷贝 30 func (r *Route) CopyFrom(src *Route) { 31 r.URL = src.URL 32 r.KeepAlive = src.KeepAlive 33 } 34 35 // Provider 路由提供者 36 type Provider interface { 37 LoadAll() ([]*Route, error) 38 Flush(full []*Route, saves []*Route, removes []*Route) error 39 }