• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






张伯雨

学习使人快乐
 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

2017年9月1日

kcp-go源码解析
摘要: kcp-go源码解析对kcp-go的源码解析,有错误之处,请一定告之。sheepbao 2017.0612概念ARQ:自动重传请求(Automatic Repeat-reQuest,ARQ)是OSI模型中数据链路层的错误纠正协议之一.RTO:Retransmission TimeOutFEC:Forward Error Correctionkcp简介kcp是一个基于udp实现快速、可靠、向前纠错的... 阅读全文
posted @ 2017-09-01 10:53 张伯雨 阅读(2454) 评论(1) 推荐(0)
 
windows.go
摘要: func LockFile(file *os.File) error { h, err := syscall.LoadLibrary("kernel32.dll") if err != nil { return err } defer syscall.FreeLibrary(h) addr, err := syscall.GetProcAd... 阅读全文
posted @ 2017-09-01 10:52 张伯雨 阅读(311) 评论(0) 推荐(0)
 
linux.go
摘要: func LockFile(file *os.File) error { return syscall.Flock(int(file.Fd()), syscall.LOCK_EX) } 阅读全文
posted @ 2017-09-01 10:51 张伯雨 阅读(157) 评论(0) 推荐(0)
 
procotol.go 源码阅读
摘要: import ( "bytes" "encoding/binary")const ( // 支持数据最大长度为 2 << 61 // DataLengthOfLenth = 8 // 支持数据最大长度为 2 << 30 DataLengthOfLenth = 4)//通讯协议处理,主要处理封包和解包的过程type Protocol struct { // ... 阅读全文
posted @ 2017-09-01 10:50 张伯雨 阅读(206) 评论(0) 推荐(0)
 
return_fun.go 源码阅读
摘要: // ***********************************************常用函数*************************************************** \\// API中生成返回结果的方法// OpAndToAndFrom[0]参数为空时,系统将指定与对端相同的操作符// OpAndToAndFrom[1]参数为空时,系统将指定与对端为接... 阅读全文
posted @ 2017-09-01 10:50 张伯雨 阅读(256) 评论(0) 推荐(0)
 
netData.go 阅读源码
摘要: package teleportimport (// "net")const ( // 返回成功 SUCCESS = 0 // 返回失败 FAILURE = -1 // 返回非法请求 LLLEGAL = -2)// 定义数据传输结构type NetData struct { // 消息体 Body interface{} // 操作代号 ... 阅读全文
posted @ 2017-09-01 10:39 张伯雨 阅读(285) 评论(0) 推荐(0)
 
conn.go 源码阅读
摘要: import ( "net")// 封装连接type Connect struct { // 标准包conn接口实例,继承该接口所有方法 net.Conn // 标记连接是否有效 Usable bool // 是否为短链接模式 Short bool // 专用写入数据缓存通道 WriteChan chan *NetData // 从连接循... 阅读全文
posted @ 2017-09-01 10:38 张伯雨 阅读(298) 评论(0) 推荐(0)
 
util.go 源码阅读
摘要: import ( "crypto/md5" "encoding/hex" "encoding/json" "fmt" "hash/crc32" "hash/fnv" "strconv")//string to hash//字符串转化为hash值 使用的是 IEEE func MakeHash(s string) string { const IE... 阅读全文
posted @ 2017-09-01 10:37 张伯雨 阅读(283) 评论(0) 推荐(0)
 
teeporxy.go
摘要: package mainimport ( "bytes" "crypto/tls" "flag" "fmt" "io" "io/ioutil" "math/rand" "net" "net/http" "net/http/httputil" "runtime" "time")// Console flags//参数解析var ... 阅读全文
posted @ 2017-09-01 10:36 张伯雨 阅读(257) 评论(0) 推荐(0)
 
sonyflake.go
摘要: // Package sonyflake implements Sonyflake, a distributed unique ID generator inspired by Twitter's Snowflake.//第一位为未使用(实际上也可作为long的符号位),接下来的41位为毫秒级时间,然后5位datacenter标识位,5位机器ID(并不算标识符,实际是为线程标识),然后12位该毫秒... 阅读全文
posted @ 2017-09-01 10:32 张伯雨 阅读(1268) 评论(0) 推荐(0)
 
dictionary.go
摘要: package segoimport "github.com/adamzy/cedar-go"// Dictionary结构体实现了一个字串前缀树,一个分词可能出现在叶子节点也有可能出现在非叶节点type Dictionary struct { trie *cedar.Cedar // Cedar 前缀树 maxTokenLength int //... 阅读全文
posted @ 2017-09-01 10:31 张伯雨 阅读(300) 评论(0) 推荐(0)
 
token.go
摘要: package sego// 字串类型,可以用来表达// 1. 一个字元,比如"中"又如"国", 英文的一个字元是一个词// 2. 一个分词,比如"中国"又如"人口"// 3. 一段文字,比如"中国有十三亿人口"type Text []byte// 一个分词type Token struct { // 分词的字串,这实际上是个字元数组 text []Text /... 阅读全文
posted @ 2017-09-01 10:31 张伯雨 阅读(434) 评论(0) 推荐(0)
 
segmenter.go
摘要: //Go中文分词package segoimport ( "bufio" "fmt" "log" "math" "os" "strconv" "strings" "unicode" "unicode/utf8")const ( minTokenFrequency = 2 // 仅从字典文件中读取大于等于此频率的分词)// 分词器结构体ty... 阅读全文
posted @ 2017-09-01 10:31 张伯雨 阅读(376) 评论(0) 推荐(0)
 
segment.go
摘要: package sego// 文本中的一个分词type Segment struct { // 分词在文本中的起始字节位置 start int // 分词在文本中的结束字节位置(不包括该位置) end int // 分词信息 token *Token}// 返回分词在文本中的起始字节位置func (s *Segment) Start() int { ret... 阅读全文
posted @ 2017-09-01 10:29 张伯雨 阅读(138) 评论(0) 推荐(0)
 
util.go
摘要: <wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;"> 阅读全文
posted @ 2017-09-01 10:27 张伯雨 阅读(348) 评论(0) 推荐(0)
 
etcd_selector.go
摘要: package clientselectorimport ( "errors" "math/rand" "net" "net/rpc" "net/url" "strconv" "strings" "time" "golang.org/x/net/context" "github.com/coreos/etcd/client" "gi... 阅读全文
posted @ 2017-09-01 10:24 张伯雨 阅读(600) 评论(0) 推荐(0)
 
ratelimit.go
摘要: // The ratelimit package provides an efficient token bucket implementation// that can be used to limit the rate of arbitrary things.// See http://en.wikipedia.org/wiki/Token_bucket.package ratelimitim... 阅读全文
posted @ 2017-09-01 10:23 张伯雨 阅读(807) 评论(0) 推荐(0)
 
reader-write.go
摘要: package ratelimitimport "io"type reader struct { r io.Reader bucket *Bucket}// Reader returns a reader that is rate limited by// the given token bucket. Each token in the bucket// represent... 阅读全文
posted @ 2017-09-01 10:23 张伯雨 阅读(344) 评论(0) 推荐(0)
 
profile.go
摘要: // Package profile provides a simple way to manage runtime/pprof// profiling of your Go application.package profileimport ( "io/ioutil" "log" "os" "os/signal" "path/filepath" "runtim... 阅读全文
posted @ 2017-09-01 10:22 张伯雨 阅读(448) 评论(0) 推荐(0)
 
man.go 阅读笔记
摘要: import ( "flag" "fmt" "github.com/Sirupsen/logrus" "log" "os" "os/signal" "syscall")var ( pConfig ProxyConfig pLog *logrus.Logger configFile = flag.String("c", "... 阅读全文
posted @ 2017-09-01 10:21 张伯雨 阅读(298) 评论(0) 推荐(0)
 
balance.go 源码阅读
摘要: import ( //"fmt" "math/rand" "net" "stathat.com/c/consistent" "time")// BackendSvr Typetype BackendSvr struct { svrStr string isUp bool // is Up or Down failTimes int}v... 阅读全文
posted @ 2017-09-01 10:20 张伯雨 阅读(281) 评论(0) 推荐(0)
 
proxy.go 源码阅读
摘要: package mainimport ( "net" "time")func initProxy() { pLog.Infof("Proxying %s -> %s\n", pConfig.Bind, pConfig.Backend) //输出服务地址 后端服务地址列表 server, err := net.Listen("tcp", pConfig.Bind) ... 阅读全文
posted @ 2017-09-01 10:20 张伯雨 阅读(373) 评论(0) 推荐(0)
 
monitor.go 源码阅读
摘要: package mainimport ( "fmt" "net/http")// 查询监控信息的接口func statsHandler(w http.ResponseWriter, r *http.Request) { _str := "" for _, v := range pBackendSvrs { _str += fmt.Sprintf("Server... 阅读全文
posted @ 2017-09-01 10:19 张伯雨 阅读(329) 评论(0) 推荐(0)
 
log.go 源码阅读
摘要: package mainimport ( "github.com/Sirupsen/logrus" "os" "path/filepath")func initLogger() error { dirPath, _ := filepath.Abs(filepath.Dir(pConfig.Log.Path)) //获取日志文件目录 if _, err := os.S... 阅读全文
posted @ 2017-09-01 10:19 张伯雨 阅读(249) 评论(0) 推荐(0)
 
config.go 源码阅读
摘要: package mainimport ( "io/ioutil" "launchpad.net/goyaml")// ProxyConfig Typetype ProxyConfig struct { Bind string `yaml:"bind"` //代理服务监听端口 WaitQueueLen int `yaml:"wait_que... 阅读全文
posted @ 2017-09-01 10:18 张伯雨 阅读(239) 评论(0) 推荐(0)
 
objectid.go源码阅读
摘要: /*具体实现理论参见 mongodb官方 objectid生成策略http://docs.mongodb.org/manual/reference/object-id/ObjectId 是一个由12字节组成的bson数据,按照字节顺序,一次代表:ObjectId is a 12-byte BSON type, constructed using:4个字节代表1970年元月一日到现在毫秒数 UN... 阅读全文
posted @ 2017-09-01 10:16 张伯雨 阅读(448) 评论(0) 推荐(0)
 
forwardPort.go
摘要: <wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;"> 阅读全文
posted @ 2017-09-01 10:15 张伯雨 阅读(313) 评论(0) 推荐(0)
 
Docker 新手入门
摘要: 简介如果您是 Docker 新手请您花大约三十分钟的时间来了解 Docker 相关的知识和内容。 Docker 与 Linux 息息相关,因此在阅读本文档之前请您确保以下条件:对 Linux 的命令行操作有一定了解,并且懂得一些基础命令。对 Linux 服务管理有一定的了解。当阅读完本文之后您可以了解什么是 Docker、使用它有什么好处、以及 Docker 具体的使用方法。为什么选择 Docke... 阅读全文
posted @ 2017-09-01 10:14 张伯雨 阅读(355) 评论(0) 推荐(0)
 
consistent.go 源码阅读
摘要: import ( "errors" "hash/crc32" "sort" "strconv" "sync")type uints []uint32 //实现 sort接口// Len returns the length of the uints array.func (x uints) Len() int { return len(x) }// Less re... 阅读全文
posted @ 2017-09-01 09:37 张伯雨 阅读(276) 评论(0) 推荐(0)
 
ranker.go
摘要: package coreimport ( "github.com/huichen/wukong/types" "github.com/huichen/wukong/utils" "log" "sort" "sync")type Ranker struct { lock struct { sync.RWMutex fields map[... 阅读全文
posted @ 2017-09-01 09:36 张伯雨 阅读(378) 评论(0) 推荐(0)
 
indexer.go
摘要: package coreimport ( "log" "math" "sort" "sync" "github.com/huichen/wukong/types" "github.com/huichen/wukong/utils")// 索引器type Indexer struct { // 从搜索键到文档列表的反向索引 // 加了读写锁以保证读写安... 阅读全文
posted @ 2017-09-01 09:36 张伯雨 阅读(267) 评论(0) 推荐(0)
 
stop_token.go
摘要: package engineimport ( "bufio" "log" "os")type StopTokens struct { stopTokens map[string]bool}// 从stopTokenFile中读入停用词,一个词一行// 文档索引建立时会跳过这些停用词func (st *StopTokens) Init(stopTokenFile string... 阅读全文
posted @ 2017-09-01 09:35 张伯雨 阅读(319) 评论(0) 推荐(0)
 
segmenter_worker.go
摘要: package engineimport ( "github.com/huichen/wukong/types")type segmenterRequest struct { docId uint64 hash uint32 data types.DocumentIndexData forceUpdate bool}func (... 阅读全文
posted @ 2017-09-01 09:34 张伯雨 阅读(226) 评论(0) 推荐(0)
 
ranker_worker.go
摘要: package engineimport ( "github.com/huichen/wukong/types")type rankerAddDocRequest struct { docId uint64 fields interface{}}type rankerRankRequest struct { docs []types.Inde... 阅读全文
posted @ 2017-09-01 09:34 张伯雨 阅读(217) 评论(0) 推荐(0)
 
persistent_storage_worker.go
摘要: package engineimport ( "bytes" "encoding/binary" "encoding/gob" "github.com/huichen/wukong/types" "sync/atomic")type persistentStorageIndexDocumentRequest struct { docId uint64 da... 阅读全文
posted @ 2017-09-01 09:34 张伯雨 阅读(174) 评论(0) 推荐(0)
 
indexer_worker.go
摘要: package engineimport ( "github.com/huichen/wukong/types" "sync/atomic")type indexerAddDocumentRequest struct { document *types.DocumentIndex forceUpdate bool}type indexerLookupRequest s... 阅读全文
posted @ 2017-09-01 09:33 张伯雨 阅读(213) 评论(0) 推荐(0)
 
engine.go
摘要: package engineimport ( "fmt" "github.com/huichen/murmur" "github.com/huichen/sego" "github.com/huichen/wukong/core" "github.com/huichen/wukong/storage" "github.com/huichen/wukong/typ... 阅读全文
posted @ 2017-09-01 09:33 张伯雨 阅读(448) 评论(0) 推荐(0)
 
storage.go
摘要: package storageimport ( "fmt" "os")const DEFAULT_STORAGE_ENGINE = "bolt" //默认存储引擎 为 bolt//存储引擎map集合 var supportedStorage = map[string]func(path string) (Storage, error){ "kv": openKVStora... 阅读全文
posted @ 2017-09-01 09:32 张伯雨 阅读(326) 评论(0) 推荐(0)
 
counter.go
摘要: package enginefunc (engine *Engine) NumTokenIndexAdded() uint64 { return engine.numTokenIndexAdded}func (engine *Engine) NumDocumentsIndexed() uint64 { return engine.numDocumentsIndexed}func (en... 阅读全文
posted @ 2017-09-01 09:32 张伯雨 阅读(148) 评论(0) 推荐(0)
 
bolt_storage.go
摘要: package storage//bolt存储引擎实现 import ( "github.com/boltdb/bolt" "time")var wukong_documents = []byte("wukong_documents")//bolt结构体 实现 同时实现storage接口type boltStorage struct { db *bolt.DB}//实现存储引... 阅读全文
posted @ 2017-09-01 09:31 张伯雨 阅读(235) 评论(0) 推荐(0)
 
kv_storage.go
摘要: package storage//kv 存储引擎实现import ( "github.com/cznic/kv" "io")//kv 存储结构体 并且实现了storage存储接口type kvStorage struct { db *kv.DB}//打开存储引擎 即:引擎map集合对应的value 值 函数的实现 key为path//返回存储引擎接口 和 err 代... 阅读全文
posted @ 2017-09-01 09:31 张伯雨 阅读(349) 评论(0) 推荐(0)
 
search_request.go
摘要: package typestype SearchRequest struct { // 搜索的短语(必须是UTF-8格式),会被分词 // 当值为空字符串时关键词会从下面的Tokens读入 Text string // 关键词(必须是UTF-8格式),当Text不为空时优先使用Text // 通常你不需要自己指定关键词,除非你运行自己的分词程序 Tokens [... 阅读全文
posted @ 2017-09-01 09:30 张伯雨 阅读(217) 评论(0) 推荐(0)
 
search_response.go
摘要: package typesimport ( "github.com/huichen/wukong/utils")type SearchResponse struct { // 搜索用到的关键词 Tokens []string // 搜索到的文档,已排序 Docs []ScoredDocument // 搜索是否超时。超时的情况下也可能会返回部分结果 Tim... 阅读全文
posted @ 2017-09-01 09:30 张伯雨 阅读(413) 评论(0) 推荐(0)
 
scoring_criteria.go
摘要: package types// 评分规则通用接口type ScoringCriteria interface { // 给一个文档评分,文档排序时先用第一个分值比较,如果 // 分值相同则转移到第二个分值,以此类推。 // 返回空切片表明该文档应该从最终排序结果中剔除。 Score(doc IndexedDocument, fields interface{}) []flo... 阅读全文
posted @ 2017-09-01 09:29 张伯雨 阅读(162) 评论(0) 推荐(0)
 
engine_init_options.go
摘要: package typesimport ( "log" "runtime")var ( // EngineInitOptions的默认值 defaultNumSegmenterThreads = runtime.NumCPU() defaultNumShards = 2 defaultIndexerBufferLeng... 阅读全文
posted @ 2017-09-01 09:28 张伯雨 阅读(444) 评论(0) 推荐(0)
 
index.go
摘要: package typestype DocumentIndex struct { // 文本的DocId DocId uint64 // 文本的关键词长 TokenLength float32 // 加入的索引键 Keywords []KeywordIndex}// 反向索引项,这实际上标注了一个(搜索键,文档)对。type KeywordIndex struc... 阅读全文
posted @ 2017-09-01 09:28 张伯雨 阅读(252) 评论(0) 推荐(0)
 
index_init_oprions.go
摘要: package types// 这些常数定义了反向索引表存储的数据类型const ( // 仅存储文档的docId DocIdsIndex = 0 // 存储关键词的词频,用于计算BM25 FrequenciesIndex = 1 // 存储关键词在文档中出现的具体字节位置(可能有多个) // 如果你希望得到关键词紧邻度数据,必须使用LocationsIndex... 阅读全文
posted @ 2017-09-01 09:28 张伯雨 阅读(141) 评论(0) 推荐(0)
 
document_index_data.go
摘要: package typestype DocumentIndexData struct { // 文档全文(必须是UTF-8格式),用于生成待索引的关键词 Content string // 文档的关键词 // 当Content不为空的时候,优先从Content中分词得到关键词。 // Tokens存在的意义在于绕过悟空内置的分词器,在引擎外部 // 进行分词和预... 阅读全文
posted @ 2017-09-01 09:27 张伯雨 阅读(176) 评论(0) 推荐(0)
 
wukong.go
摘要: package wukongimport ( _ "github.com/boltdb/bolt" _ "github.com/cznic/kv" _ "github.com/huichen/murmur" _ "github.com/huichen/sego") 阅读全文
posted @ 2017-09-01 09:26 张伯雨 阅读(194) 评论(0) 推荐(0)
 
util.go
摘要: package utils//int数字比较func AbsInt(a int) int { if a < 0 { return -a } return a}func MinInt(a, b int) int { if a < b { return a } return b} 阅读全文
posted @ 2017-09-01 09:26 张伯雨 阅读(165) 评论(0) 推荐(0)
 
volume_manager.go
摘要: package managerimport ( "net/http" "github.com/030io/whalefs/manager/volume" "os" "io/ioutil" "strings" "strconv" "fmt" "time" "github.com/030io/whalefs/master/api" "gith... 阅读全文
posted @ 2017-09-01 09:25 张伯雨 阅读(261) 评论(0) 推荐(0)
 
admin-handlers.go
摘要: package managerimport ( "net/http" "regexp" "strconv" "io" "fmt" "github.com/030io/whalefs/manager/volume" "gopkg.in/redis.v2" "os")var ( postVolumeUrl *regexp.Regexp //提交卷... 阅读全文
posted @ 2017-09-01 09:24 张伯雨 阅读(174) 评论(0) 推荐(0)
 
mime.go
摘要: package managerimport ( "mime" "path")//初始化数据func init() { if mime.TypeByExtension(".txt") == "" { panic("mime.types not found") }}//获取文件扩展名对应的媒体(内容)类型func get_content_type(filepath... 阅读全文
posted @ 2017-09-01 09:24 张伯雨 阅读(200) 评论(0) 推荐(0)
 
public_handers.go
摘要: package managerimport ( "net/http" "regexp" "strconv" "io" "strings" "fmt" "time")var publicUrlRegex *regexp.Regexpfunc init() { var err error publicUrlRegex, err = regexp.C... 阅读全文
posted @ 2017-09-01 09:24 张伯雨 阅读(199) 评论(0) 推荐(0)
 
index_levedb.go
摘要: package volumeimport ( "github.com/syndtr/goleveldb/leveldb" "encoding/binary" "path/filepath" "strconv")//文件索引结构体type LevelDBIndex struct { path string db *leveldb.DB}//创建leveldb索... 阅读全文
posted @ 2017-09-01 09:22 张伯雨 阅读(240) 评论(0) 推荐(0)
 
status.go
摘要: package volumeimport ( "github.com/syndtr/goleveldb/leveldb" "sync" "encoding/binary" "github.com/syndtr/goleveldb/leveldb/util" "errors" "path/filepath" "strconv" "fmt")const ... 阅读全文
posted @ 2017-09-01 09:22 张伯雨 阅读(226) 评论(0) 推荐(0)
 
volume.go
摘要: package volumeimport ( "os" "path/filepath" "strconv" "sync" "time" "encoding/binary" "errors")var ( TruncateSize uint64 = 1 = MaxVolumeSize { return } //清空指定偏移... 阅读全文
posted @ 2017-09-01 09:22 张伯雨 阅读(251) 评论(0) 推荐(0)
 
file.go
摘要: package volumeimport ( "time" "encoding/binary" "errors" "os" "io")//文件基本信息结构体type FileInfo struct { Fid uint64 Offset uint64 Size uint64 Ctime time.Time Mt... 阅读全文
posted @ 2017-09-01 09:21 张伯雨 阅读(544) 评论(0) 推荐(0)
 
index.go
摘要: package volumeimport "io"//文件基本读写 存在与否 关闭type Index interface { Has(fid uint64) bool Get(fid uint64) (*FileInfo, error) Set(fi *FileInfo) error Delete(fid uint64) error io.Closer} 阅读全文
posted @ 2017-09-01 09:21 张伯雨 阅读(177) 评论(0) 推荐(0)
 
upload.go
摘要: package apiimport ( "os" "bytes" "mime/multipart" "path/filepath" "io" "net/http" "errors" "fmt" "io/ioutil")//上传文件到指定的位置func Upload(host string, port int, vid uint64, fid u... 阅读全文
posted @ 2017-09-01 09:20 张伯雨 阅读(221) 评论(0) 推荐(0)
 
get.go
摘要: package apiimport ( "net/http" "fmt" "io/ioutil")const bufferSize = 512 * 1024//获取空间文件func Get(host string, port int, vid uint64, fid uint64, filename string) ([]byte, error) { url := fmt.... 阅读全文
posted @ 2017-09-01 09:19 张伯雨 阅读(181) 评论(0) 推荐(0)
 
delete.go
摘要: package apiimport ( "net/http" "fmt" "io/ioutil" "errors")//删除空间资源func Delete(host string, port int, vid uint64, fid uint64, filename string) error { url := fmt.Sprintf("http://%s:%d/%d... 阅读全文
posted @ 2017-09-01 09:18 张伯雨 阅读(116) 评论(0) 推荐(0)
 
create_volume.go
摘要: package apiimport ( "net/http" "io/ioutil" "errors" "fmt")//创建存储空间func CreateVolume(host string, port int, vid uint64) error { url := fmt.Sprintf("http://%s:%d/%d/", host, port, vid) ... 阅读全文
posted @ 2017-09-01 09:17 张伯雨 阅读(151) 评论(0) 推荐(0)
 
upload.go
摘要: package apiimport ( "fmt" "os" "bytes" "mime/multipart" "path/filepath" "io" "net/http" "errors" "io/ioutil")func Upload(host string, port int, dst string, src string) (err ... 阅读全文
posted @ 2017-09-01 09:16 张伯雨 阅读(182) 评论(0) 推荐(0)
 
get.go
摘要: package apiimport ( "net/http" "fmt" "io/ioutil")func Get(host string, port int, filePath string) ([]byte, error) { if filePath[0] == '/' { filePath = filePath[1:] } var url s... 阅读全文
posted @ 2017-09-01 09:15 张伯雨 阅读(166) 评论(0) 推荐(0)
 
delete.go
摘要: package apiimport ( "fmt" "net/http" "io/ioutil" "errors")func Delete(host string, port int, filePath string) error { if filePath[0] == '/' { filePath = filePath[1:] } var ... 阅读全文
posted @ 2017-09-01 09:15 张伯雨 阅读(104) 评论(0) 推荐(0)
 
heartbeat.go
摘要: package apiimport ( "github.com/030io/whalefs/master" "fmt" "encoding/json" "bytes" "net/http" "io/ioutil")func Heartbeat(host string, port int, vms *master.VolumeManagerStatus) erro... 阅读全文
posted @ 2017-09-01 09:15 张伯雨 阅读(241) 评论(0) 推荐(0)
 
handler.go
摘要: package masterimport ( "net/http" "io/ioutil" "encoding/json" "time" "strings" "sync" "math/rand" "path/filepath" "fmt" "os" "github.com/030io/whalefs/utils/uuid")type... 阅读全文
posted @ 2017-09-01 09:13 张伯雨 阅读(254) 评论(0) 推荐(0)
 
uuid.go
摘要: package uuidimport "time"func GenerateUUID() uint64 { return uint64(time.Now().UnixNano()) //即从时间点January 1, 1970 UTC到时间点t所经过的时间(单位纳秒)} 阅读全文
posted @ 2017-09-01 09:12 张伯雨 阅读(212) 评论(0) 推荐(0)
 
disk.go
摘要: package diskimport "syscall"//空间使用结构体type DiskStatus struct { Size uint64 Used uint64 Free uint64}//空间使用情况func DiskUsage(path string) (disk *DiskStatus, err error) { fs := new(syscall.St... 阅读全文
posted @ 2017-09-01 09:11 张伯雨 阅读(259) 评论(0) 推荐(0)
 
kingpin_parser.go
摘要: package kingpin_parserimport ( "strconv" "gopkg.in/alecthomas/kingpin.v2" "fmt")type size uint64//单位换算func (s *size) Set(value string) error { num, err := strconv.ParseUint(value[:len(valu... 阅读全文
posted @ 2017-09-01 09:11 张伯雨 阅读(712) 评论(0) 推荐(0)
 
logrus_hook.go
摘要: package logrus_hookimport ( "runtime" "strings" "path/filepath" log "github.com/Sirupsen/logrus")type ContextHook struct {}func (hook ContextHook)Levels() []log.Level { return log.AllLe... 阅读全文
posted @ 2017-09-01 09:06 张伯雨 阅读(687) 评论(0) 推荐(0)
 
plugin.go 源码阅读
摘要: package pingoimport ( "bufio" "errors" "fmt" "io" "log" "net" "net/rpc" "os" "os/exec" "strings" "time")var ( errInvalidMessage = ErrInvalidMessage(errors.New(... 阅读全文
posted @ 2017-09-01 09:03 张伯雨 阅读(265) 评论(0) 推荐(0)