|
| 1 | +# k2hash_go |
| 2 | + |
| 3 | +### Overview |
| 4 | + |
| 5 | +**k2hash_go** implements a [k2hash](https://k2hash.antpick.ax/) client in golang. |
| 6 | + |
| 7 | +### Install |
| 8 | + |
| 9 | +Firstly you must install the [k2hash](https://k2hash.antpick.ax/) shared library. |
| 10 | +``` |
| 11 | +$ curl -o- https://raw.github.com/yahoojapan/k2hash_go/master/utils/libk2hash.sh | bash |
| 12 | +``` |
| 13 | +You can install **k2hash** library step by step from [source code](https://github.com/yahoojapan/k2hash). See [Build](https://k2hash.antpick.ax/build.html) for details. |
| 14 | + |
| 15 | +After you make sure you set the [GOPATH](https://github.com/golang/go/wiki/SettingGOPATH) environment, download the **k2hash_go** package. |
| 16 | +``` |
| 17 | +$ go get -u github.com/yahoojapan/k2hash_go |
| 18 | +``` |
| 19 | + |
| 20 | +### Usage |
| 21 | + |
| 22 | +Here is a simple example of **k2hash_go** which save a key and get it. |
| 23 | + |
| 24 | +```golang |
| 25 | +package main |
| 26 | + |
| 27 | +import ( |
| 28 | + "fmt" |
| 29 | + "os" |
| 30 | + |
| 31 | + "github.com/yahoojapan/k2hash_go/k2hash" |
| 32 | +) |
| 33 | + |
| 34 | +func SetAndGet() { |
| 35 | + // 1. Instantiate K2hash class |
| 36 | + file, _ := k2hash.NewK2hash("/tmp/test.k2h") |
| 37 | + defer file.Close() |
| 38 | + ok, err := file.Set("hello", "world") |
| 39 | + if ok != true { |
| 40 | + fmt.Fprintf(os.Stderr, "file.Set(hello, world) returned false, err %v\n", err) |
| 41 | + } |
| 42 | + // 2. Get |
| 43 | + // 2.1. no args |
| 44 | + val, err := file.Get("hello") |
| 45 | + if val == nil || err != nil { |
| 46 | + fmt.Fprintf(os.Stderr, "file.Get(hello) returned val %v err %v\n", val, err) |
| 47 | + return |
| 48 | + } |
| 49 | + fmt.Printf("val = %v, err = %v\n", val.String(), err) |
| 50 | +} |
| 51 | + |
| 52 | +func main() { |
| 53 | + SetAndGet() |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +### Development |
| 58 | + |
| 59 | +Here is the step to start developing **k2hash_go**. |
| 60 | + |
| 61 | +- Debian / Ubuntu |
| 62 | + |
| 63 | +```bash |
| 64 | +#!/bin/sh |
| 65 | + |
| 66 | +sudo apt-get update -y && sudo apt-get install curl git -y && curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.deb.sh | sudo bash |
| 67 | +sudo apt-get install libfullock-dev k2hash-dev -y |
| 68 | +go get github.com/yahoojapan/k2hash_go/k2hash |
| 69 | + |
| 70 | +exit 0 |
| 71 | +``` |
| 72 | + |
| 73 | +- CentOS / Fedora |
| 74 | + |
| 75 | +```bash |
| 76 | +#!/bin/sh |
| 77 | + |
| 78 | +sudo dnf makecache && sudo yum install curl git -y && curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.rpm.sh | sudo bash |
| 79 | +sudo dnf install libfullock-devel k2hash-devel -y |
| 80 | +go get github.com/yahoojapan/k2hash_go/k2hash |
| 81 | + |
| 82 | +exit 0 |
| 83 | +``` |
| 84 | + |
| 85 | +### Documents |
| 86 | + - [About K2HASH](https://k2hash.antpick.ax/) |
| 87 | + - [About AntPickax](https://antpick.ax/) |
| 88 | + |
| 89 | +### License |
| 90 | + |
| 91 | +MIT License. See the LICENSE file. |
| 92 | + |
| 93 | +## AntPickax |
| 94 | + |
| 95 | +[AntPickax](https://antpick.ax/) is |
| 96 | + - an open source team in [Yahoo Japan Corporation](https://about.yahoo.co.jp/info/en/company/). |
| 97 | + - a product family of open source software developed by [AntPickax](https://antpick.ax/). |
| 98 | + |
0 commit comments