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






张伯雨

学习使人快乐
 
 

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

09 2017 档案

 
TCP-Java--图谱
摘要: 阅读全文
posted @ 2017-09-30 15:10 张伯雨 阅读(440) 评论(0) 推荐(1)
理解、学习与使用 Java 中的 Optional
摘要:从 Java 8 引入的一个很有趣的特性是 Optional 类。Optional 类主要解决的问题是臭名昭著的空指针异常(NullPointerException) —— 每个 Java 程序员都非常了解的异常。本质上,这是一个包含有可选值的包装类,这意味着 Optional 类既可以含有对象也可以为空。Optional 是 Java 实现函数式编程的强劲一步,并且帮助在范式中实现。但是 Op... 阅读全文
posted @ 2017-09-23 09:45 张伯雨 阅读(461728) 评论(26) 推荐(83)
Rustlang语言逐行处理文件的基本方法
摘要:文件操作需求:将文件中的内容按行读取出来,然后对改行的数据进行处理,最后将处理后的行数据存放到新的文件中。使用RUST来处理的方法如下。首先引入需要的标准库:use std::io::prelude::*; use std::fs::File; use std::io::BufWriter; use std::io::BufReader; 然后将处理函数放到一个main函数中,这是我处... 阅读全文
posted @ 2017-09-21 19:09 张伯雨 阅读(1575) 评论(0) 推荐(0)
时序数据库InfluxDB使用详解
摘要:1 安装配置这里说一下使用docker容器运行influxdb的步骤,物理机安装请参照官方文档。拉取镜像文件后运行即可,当前最新版本是1.3.5。启动容器时设置挂载的数据目录和开放端口。InfluxDB的操作语法InfluxQL与SQL基本一致,也提供了一个类似mysql-client的名为influx的CLI。InfluxDB本身是支持分布式部署多副本存储的,本文介绍都是针对的单节点单副本。# ... 阅读全文
posted @ 2017-09-11 09:55 张伯雨 阅读(7985) 评论(0) 推荐(0)
高级主题
摘要:外部函数接口在Rust中,通过外部函数接口 (foreign function interface) 可以直接调用C语言库:extern crate libc; use libc::size_t; #[link(name = "snappy")] extern { fn snappy_max_compressed_length(source_length: size_t) -> size... 阅读全文
posted @ 2017-09-09 18:00 张伯雨 阅读(294) 评论(0) 推荐(0)
编程范式
摘要:编程范式Rust是一个多范式 (multi-paradigm) 的编译型语言。除了通常的结构化、命令式编程外, 还支持以下范式。函数式编程Rust使用闭包 (closure) 来创建匿名函数:let num = 5; let plus_num = |x: i32| x + num;其中闭包plus_num借用了它作用域中的let绑定num。如果要让闭包获得所有权, 可以使用move关键字:let ... 阅读全文
posted @ 2017-09-09 17:58 张伯雨 阅读(792) 评论(0) 推荐(0)
内存安全
摘要:Rust推崇安全与速度至上,它没有垃圾回收机制,却成功实现了内存安全 (memory safety)。所有权在Rust中,所有权 (ownership) 系统是零成本抽象 (zero-cost abstraction) 的一个主要例子。 对所有权的分析是在编译阶段就完成的,并不带来任何运行时成本 (run-time cost)。 默认情况下,Rust是在栈 (stack) 上分配内存,对栈上空间变... 阅读全文
posted @ 2017-09-09 17:48 张伯雨 阅读(1412) 评论(0) 推荐(0)
程序测试
摘要:程序测试测试属性在测试函数前加上#[test]属性:#[test] fn it_works() { assert!(false); }其中assert!宏接受一个参数,如果参数为false,它会导致panic!。 运行cargo test命令,可见该测试失败。如果要反转测试失败, 可以加上#[should_panic]属性:测试模块在测试模块前加上#[cfg(test)]属性:测试目录对于... 阅读全文
posted @ 2017-09-09 17:01 张伯雨 阅读(220) 评论(0) 推荐(0)
模块系统
摘要:模块系统Rust有两个与模块 (module) 系统相关的独特术语:crate和module, 其中包装箱 (crate) 与其它语言中的 libary 或者 package 作用一样。 每个包装箱都有一个隐藏的根模块,在根模块下可以定义一个子模块树, 其路径采用::作为分隔符。包装箱由条目 (item) 构成,多个条目通过模块组织在一起。定义模块使用mod关键字定义我们的模块:// in src... 阅读全文
posted @ 2017-09-09 16:25 张伯雨 阅读(263) 评论(0) 推荐(0)
控制结构
摘要:IfIf是分支 (branch) 的一种特殊形式,也可以使用else和else if。 与C语言不同的是,逻辑条件不需要用小括号括起来,但是条件后面必须跟一个代码块。 Rust中的if是一个表达式 (expression),可以赋给一个变量:let x = 5; let y = if x == 5 { 10 } else { 15 };Rust是基于表达式的编程语言,有且仅有两种语句 (stat... 阅读全文
posted @ 2017-09-09 15:59 张伯雨 阅读(293) 评论(0) 推荐(0)
基本语法
摘要:变量绑定在Rust中,变量绑定 (variable bindings) 是通过let关键字声明的:let x = 5; let mut x = 5; let x: i32 = 5; let (a, b) = (3, 4);其中变量类型如i32一般都是可以省略的,因为Rust使用了类型推断 (type inference)。 Rust还通过模式匹配 (pattern matching) 对变量进行解... 阅读全文
posted @ 2017-09-09 11:49 张伯雨 阅读(511) 评论(0) 推荐(0)
Go-技篇第一 技巧杂烩
摘要:Go-技篇第一 技巧杂烩一句话技巧把你面向对象的大脑扔到家里吧,去拥抱接口。@mikegehard学习如何使用Go的方式做事,不要把别的的编程风格强行用在Go里面。@DrNic多用接口总比少用好。@evanphx拥抱这种简洁、并行、工整的语言。@francesc阅读官网golang.org上所有的文档,真是棒呆了。@vbatts别忘了用gofmt。@darkhelmetlive多读源代码。@DrN... 阅读全文
posted @ 2017-09-09 11:46 张伯雨 阅读(371) 评论(0) 推荐(0)
Go-技篇第二 命名规范
摘要:优秀的命名优秀的命名应当是一贯的、短小的、精确的。所谓一贯,就是说同一个意义在不同的环境下的命名应当一致,譬如依赖关系,不要在一个方法中命名为depend,另一个方法中命名为rely。所谓短小,不必多言,当命名过长的时候,读者可能更关注命名本身,而忽视真正的逻辑内容。所谓精确,就是命名达意、易于理解首条经验声明位置与使用位置越远,则命名应当越长。骆驼命名法Go语言应该使用 MixedCa... 阅读全文
posted @ 2017-09-09 11:37 张伯雨 阅读(294) 评论(0) 推荐(0)
微服务的4个设计原则和19个解决方案
摘要:转载本文需注明出处:微信公众号EAWorld,违者必究。微服务架构现在是谈到企业应用架构时必聊的话题,微服务之所以火热也是因为相对之前的应用开发方式有很多优点,如更灵活、更能适应现在需求快速变更的大环境。本文将介绍微服务架构的演进、优缺点和微服务应用的设计原则,然后着重介绍作为一个“微服务应用平台”需要提供哪些能力、解决哪些问题才能更好的支撑企业应用架构。微服务平台也是我目前正在参与的,还在研发过... 阅读全文
posted @ 2017-09-08 11:56 张伯雨 阅读(774) 评论(0) 推荐(0)
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 张伯雨 阅读(2464) 评论(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 张伯雨 阅读(313) 评论(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 张伯雨 阅读(159) 评论(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 张伯雨 阅读(209) 评论(0) 推荐(0)
return_fun.go 源码阅读
摘要:// ***********************************************常用函数*************************************************** \\// API中生成返回结果的方法// OpAndToAndFrom[0]参数为空时,系统将指定与对端相同的操作符// OpAndToAndFrom[1]参数为空时,系统将指定与对端为接... 阅读全文
posted @ 2017-09-01 10:50 张伯雨 阅读(257) 评论(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 张伯雨 阅读(287) 评论(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 张伯雨 阅读(301) 评论(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 张伯雨 阅读(287) 评论(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 张伯雨 阅读(260) 评论(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 张伯雨 阅读(1276) 评论(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 张伯雨 阅读(379) 评论(0) 推荐(0)
token.go
摘要:package sego// 字串类型,可以用来表达// 1. 一个字元,比如"中"又如"国", 英文的一个字元是一个词// 2. 一个分词,比如"中国"又如"人口"// 3. 一段文字,比如"中国有十三亿人口"type Text []byte// 一个分词type Token struct { // 分词的字串,这实际上是个字元数组 text []Text /... 阅读全文
posted @ 2017-09-01 10:31 张伯雨 阅读(438) 评论(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 张伯雨 阅读(302) 评论(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 张伯雨 阅读(142) 评论(0) 推荐(0)
util.go
摘要:<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;"> 阅读全文
posted @ 2017-09-01 10:27 张伯雨 阅读(351) 评论(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 张伯雨 阅读(613) 评论(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 张伯雨 阅读(811) 评论(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 张伯雨 阅读(347) 评论(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 张伯雨 阅读(458) 评论(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 张伯雨 阅读(299) 评论(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 张伯雨 阅读(376) 评论(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 张伯雨 阅读(283) 评论(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)
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 张伯雨 阅读(332) 评论(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 张伯雨 阅读(241) 评论(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 张伯雨 阅读(451) 评论(0) 推荐(0)
forwardPort.go
摘要:<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;"> 阅读全文
posted @ 2017-09-01 10:15 张伯雨 阅读(314) 评论(0) 推荐(0)
Docker 新手入门
摘要:简介如果您是 Docker 新手请您花大约三十分钟的时间来了解 Docker 相关的知识和内容。 Docker 与 Linux 息息相关,因此在阅读本文档之前请您确保以下条件:对 Linux 的命令行操作有一定了解,并且懂得一些基础命令。对 Linux 服务管理有一定的了解。当阅读完本文之后您可以了解什么是 Docker、使用它有什么好处、以及 Docker 具体的使用方法。为什么选择 Docke... 阅读全文
posted @ 2017-09-01 10:14 张伯雨 阅读(357) 评论(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 张伯雨 阅读(277) 评论(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 张伯雨 阅读(270) 评论(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 张伯雨 阅读(382) 评论(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 张伯雨 阅读(322) 评论(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 张伯雨 阅读(176) 评论(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)
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 张伯雨 阅读(229) 评论(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 张伯雨 阅读(449) 评论(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 张伯雨 阅读(214) 评论(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 张伯雨 阅读(330) 评论(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 张伯雨 阅读(149) 评论(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 张伯雨 阅读(239) 评论(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 张伯雨 阅读(353) 评论(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 张伯雨 阅读(415) 评论(0) 推荐(0)
scoring_criteria.go
摘要:package types// 评分规则通用接口type ScoringCriteria interface { // 给一个文档评分,文档排序时先用第一个分值比较,如果 // 分值相同则转移到第二个分值,以此类推。 // 返回空切片表明该文档应该从最终排序结果中剔除。 Score(doc IndexedDocument, fields interface{}) []flo... 阅读全文
posted @ 2017-09-01 09:29 张伯雨 阅读(164) 评论(0) 推荐(0)
engine_init_options.go
摘要:package typesimport ( "log" "runtime")var ( // EngineInitOptions的默认值 defaultNumSegmenterThreads = runtime.NumCPU() defaultNumShards = 2 defaultIndexerBufferLeng... 阅读全文
posted @ 2017-09-01 09:28 张伯雨 阅读(445) 评论(0) 推荐(0)
index.go
摘要:package typestype DocumentIndex struct { // 文本的DocId DocId uint64 // 文本的关键词长 TokenLength float32 // 加入的索引键 Keywords []KeywordIndex}// 反向索引项,这实际上标注了一个(搜索键,文档)对。type KeywordIndex struc... 阅读全文
posted @ 2017-09-01 09:28 张伯雨 阅读(253) 评论(0) 推荐(0)
index_init_oprions.go
摘要:package types// 这些常数定义了反向索引表存储的数据类型const ( // 仅存储文档的docId DocIdsIndex = 0 // 存储关键词的词频,用于计算BM25 FrequenciesIndex = 1 // 存储关键词在文档中出现的具体字节位置(可能有多个) // 如果你希望得到关键词紧邻度数据,必须使用LocationsIndex... 阅读全文
posted @ 2017-09-01 09:28 张伯雨 阅读(142) 评论(0) 推荐(0)
document_index_data.go
摘要:package typestype DocumentIndexData struct { // 文档全文(必须是UTF-8格式),用于生成待索引的关键词 Content string // 文档的关键词 // 当Content不为空的时候,优先从Content中分词得到关键词。 // Tokens存在的意义在于绕过悟空内置的分词器,在引擎外部 // 进行分词和预... 阅读全文
posted @ 2017-09-01 09:27 张伯雨 阅读(178) 评论(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 张伯雨 阅读(195) 评论(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 张伯雨 阅读(167) 评论(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 张伯雨 阅读(175) 评论(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 张伯雨 阅读(202) 评论(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 张伯雨 阅读(202) 评论(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 张伯雨 阅读(242) 评论(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 张伯雨 阅读(229) 评论(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 张伯雨 阅读(254) 评论(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 张伯雨 阅读(546) 评论(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 张伯雨 阅读(178) 评论(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 张伯雨 阅读(223) 评论(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 张伯雨 阅读(182) 评论(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 张伯雨 阅读(117) 评论(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 张伯雨 阅读(152) 评论(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 张伯雨 阅读(184) 评论(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 张伯雨 阅读(167) 评论(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 张伯雨 阅读(245) 评论(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 张伯雨 阅读(263) 评论(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 张伯雨 阅读(213) 评论(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 张伯雨 阅读(260) 评论(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 张伯雨 阅读(714) 评论(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 张伯雨 阅读(690) 评论(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 张伯雨 阅读(270) 评论(0) 推荐(0)