├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── client.go
├── client_test.go
├── cmd
├── android
│ ├── doc.go
│ └── magopie
│ │ ├── .gitignore
│ │ ├── app
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ ├── androidTest
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── bullercodeworks
│ │ │ │ └── magopie
│ │ │ │ └── ApplicationTest.java
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── bullercodeworks
│ │ │ │ │ └── magopie
│ │ │ │ │ ├── AboutActivity.java
│ │ │ │ │ ├── ConfigActivity.java
│ │ │ │ │ ├── MainActivity.java
│ │ │ │ │ ├── State.java
│ │ │ │ │ └── adapters
│ │ │ │ │ └── ResultAdapter.java
│ │ │ └── res
│ │ │ │ ├── drawable-hdpi
│ │ │ │ ├── magnet.png
│ │ │ │ ├── magopie.png
│ │ │ │ ├── magopie_android_icon.png
│ │ │ │ └── magopie_logo_text.png
│ │ │ │ ├── drawable-ldpi
│ │ │ │ ├── magnet.png
│ │ │ │ ├── magopie.png
│ │ │ │ ├── magopie_android_icon.png
│ │ │ │ └── magopie_logo_text.png
│ │ │ │ ├── drawable-mdpi
│ │ │ │ ├── magnet.png
│ │ │ │ ├── magopie.png
│ │ │ │ ├── magopie_android_icon.png
│ │ │ │ └── magopie_logo_text.png
│ │ │ │ ├── drawable-xhdpi
│ │ │ │ ├── magnet.png
│ │ │ │ ├── magopie.png
│ │ │ │ ├── magopie_android_icon.png
│ │ │ │ └── magopie_logo_text.png
│ │ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── magnet.png
│ │ │ │ ├── magopie.png
│ │ │ │ ├── magopie_android_icon.png
│ │ │ │ └── magopie_logo_text.png
│ │ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── magnet.png
│ │ │ │ ├── magopie.png
│ │ │ │ ├── magopie_android_icon.png
│ │ │ │ └── magopie_logo_text.png
│ │ │ │ ├── layout
│ │ │ │ ├── activity_about.xml
│ │ │ │ ├── content_config.xml
│ │ │ │ ├── content_main.xml
│ │ │ │ └── torrent_list_row.xml
│ │ │ │ ├── menu
│ │ │ │ ├── menu_main.xml
│ │ │ │ └── popup_menu.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── bullercodeworks
│ │ │ └── magopie
│ │ │ └── ExampleUnitTest.java
│ │ ├── build.gradle
│ │ ├── gradle.properties
│ │ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ │ ├── gradlew
│ │ ├── gradlew.bat
│ │ ├── magopie-go
│ │ └── build.gradle
│ │ └── settings.gradle
├── magopie-cui
│ ├── .gitignore
│ ├── main.go
│ ├── screen.go
│ ├── screen_about.go
│ └── screen_search.go
└── magopie
│ ├── .gitignore
│ ├── doc.go
│ ├── errors.go
│ ├── main.go
│ ├── server.go
│ ├── server_test.go
│ ├── site_kat.go
│ ├── site_kat_test.go
│ ├── site_tpb.go
│ ├── site_tpb_test.go
│ ├── sitedb.go
│ ├── sitedb_test.go
│ ├── test_helpers_test.go
│ └── testdata
│ ├── kat_ubuntu.xml
│ └── tpb_ubuntu
├── doc.go
├── logo.png
├── margo.png
├── site.go
├── torrent.go
├── util.go
├── util_test.go
└── vendor
├── github.com
├── PuerkitoBio
│ └── goquery
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── array.go
│ │ ├── doc.go
│ │ ├── expand.go
│ │ ├── filter.go
│ │ ├── iteration.go
│ │ ├── manipulation.go
│ │ ├── property.go
│ │ ├── query.go
│ │ ├── traversal.go
│ │ ├── type.go
│ │ └── utilities.go
├── andybalholm
│ └── cascadia
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── parser.go
│ │ └── selector.go
├── br0xen
│ └── termbox-util
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── termbox_alertmodal.go
│ │ ├── termbox_asciiart.go
│ │ ├── termbox_confirmmodal.go
│ │ ├── termbox_dropmenu.go
│ │ ├── termbox_frame.go
│ │ ├── termbox_inputfield.go
│ │ ├── termbox_inputmodal.go
│ │ ├── termbox_label.go
│ │ ├── termbox_menu.go
│ │ ├── termbox_progressbar.go
│ │ ├── termbox_scrollframe.go
│ │ └── termbox_util.go
├── dustin
│ └── go-humanize
│ │ ├── LICENSE
│ │ ├── README.markdown
│ │ ├── big.go
│ │ ├── bigbytes.go
│ │ ├── bytes.go
│ │ ├── comma.go
│ │ ├── ftoa.go
│ │ ├── humanize.go
│ │ ├── number.go
│ │ ├── ordinals.go
│ │ ├── si.go
│ │ └── times.go
├── gorilla
│ ├── context
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── context.go
│ │ └── doc.go
│ └── mux
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── doc.go
│ │ ├── mux.go
│ │ ├── regexp.go
│ │ └── route.go
├── justinas
│ └── alice
│ │ ├── LICENSE
│ │ ├── README.md
│ │ └── chain.go
├── kr
│ └── fs
│ │ ├── LICENSE
│ │ ├── Readme
│ │ ├── filesystem.go
│ │ └── walk.go
├── mattn
│ └── go-runewidth
│ │ ├── README.mkd
│ │ ├── runewidth.go
│ │ ├── runewidth_js.go
│ │ ├── runewidth_posix.go
│ │ └── runewidth_windows.go
├── nsf
│ └── termbox-go
│ │ ├── AUTHORS
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── api.go
│ │ ├── api_common.go
│ │ ├── api_windows.go
│ │ ├── collect_terminfo.py
│ │ ├── syscalls.go
│ │ ├── syscalls_darwin.go
│ │ ├── syscalls_darwin_amd64.go
│ │ ├── syscalls_freebsd.go
│ │ ├── syscalls_linux.go
│ │ ├── syscalls_netbsd.go
│ │ ├── syscalls_openbsd.go
│ │ ├── syscalls_windows.go
│ │ ├── termbox.go
│ │ ├── termbox_common.go
│ │ ├── termbox_windows.go
│ │ ├── terminfo.go
│ │ └── terminfo_builtin.go
├── pborman
│ └── uuid
│ │ ├── CONTRIBUTING.md
│ │ ├── CONTRIBUTORS
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── dce.go
│ │ ├── doc.go
│ │ ├── hash.go
│ │ ├── json.go
│ │ ├── node.go
│ │ ├── sql.go
│ │ ├── time.go
│ │ ├── util.go
│ │ ├── uuid.go
│ │ ├── version1.go
│ │ └── version4.go
├── pkg
│ └── sftp
│ │ ├── CONTRIBUTORS
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── attrs.go
│ │ ├── attrs_stubs.go
│ │ ├── attrs_unix.go
│ │ ├── client.go
│ │ ├── debug.go
│ │ ├── packet.go
│ │ ├── release.go
│ │ ├── server.go
│ │ ├── server_stubs.go
│ │ ├── server_unix.go
│ │ └── sftp.go
└── spf13
│ └── afero
│ ├── LICENSE.txt
│ ├── README.md
│ ├── afero.go
│ ├── appveyor.yml
│ ├── basepath.go
│ ├── cacheOnReadFs.go
│ ├── const_bsds.go
│ ├── const_win_unix.go
│ ├── copyOnWriteFs.go
│ ├── httpFs.go
│ ├── ioutil.go
│ ├── mem
│ ├── dir.go
│ ├── dirmap.go
│ └── file.go
│ ├── memmap.go
│ ├── memradix.go
│ ├── os.go
│ ├── path.go
│ ├── readonlyfs.go
│ ├── regexpfs.go
│ ├── sftp.go
│ ├── sftp
│ └── file.go
│ ├── sftp_test_go
│ ├── unionFile.go
│ └── util.go
├── golang.org
└── x
│ ├── crypto
│ ├── LICENSE
│ ├── PATENTS
│ ├── curve25519
│ │ ├── const_amd64.s
│ │ ├── cswap_amd64.s
│ │ ├── curve25519.go
│ │ ├── doc.go
│ │ ├── freeze_amd64.s
│ │ ├── ladderstep_amd64.s
│ │ ├── mont25519_amd64.go
│ │ ├── mul_amd64.s
│ │ └── square_amd64.s
│ └── ssh
│ │ ├── buffer.go
│ │ ├── certs.go
│ │ ├── channel.go
│ │ ├── cipher.go
│ │ ├── client.go
│ │ ├── client_auth.go
│ │ ├── common.go
│ │ ├── connection.go
│ │ ├── doc.go
│ │ ├── handshake.go
│ │ ├── kex.go
│ │ ├── keys.go
│ │ ├── mac.go
│ │ ├── messages.go
│ │ ├── mux.go
│ │ ├── server.go
│ │ ├── session.go
│ │ ├── tcpip.go
│ │ └── transport.go
│ ├── net
│ ├── LICENSE
│ ├── PATENTS
│ └── html
│ │ ├── atom
│ │ ├── atom.go
│ │ ├── gen.go
│ │ └── table.go
│ │ ├── const.go
│ │ ├── doc.go
│ │ ├── doctype.go
│ │ ├── entity.go
│ │ ├── escape.go
│ │ ├── foreign.go
│ │ ├── node.go
│ │ ├── parse.go
│ │ ├── render.go
│ │ └── token.go
│ └── text
│ ├── LICENSE
│ ├── PATENTS
│ ├── transform
│ └── transform.go
│ └── unicode
│ └── norm
│ ├── composition.go
│ ├── forminfo.go
│ ├── input.go
│ ├── iter.go
│ ├── maketables.go
│ ├── normalize.go
│ ├── readwriter.go
│ ├── tables.go
│ ├── transform.go
│ ├── trie.go
│ └── triegen.go
└── vendor.json
/.gitignore:
--------------------------------------------------------------------------------
1 | *.swp
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - 1.6
5 | - tip
6 |
7 | matrix:
8 | fast_finish: true
9 | allow_failures:
10 | - go: tip
11 |
12 | install: true # Bypass installing deps on travis to force vendoring
13 |
14 | script: go test -v -race ./...
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2016 Magopie Authors
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | this software and associated documentation files (the "Software"), to deal in
6 | the Software without restriction, including without limitation the rights to
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | of the Software, and to permit persons to whom the Software is furnished to do
9 | so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
--------------------------------------------------------------------------------
/client_test.go:
--------------------------------------------------------------------------------
1 | package magopie
2 |
3 | import (
4 | "encoding/json"
5 | "net/http"
6 | "net/http/httptest"
7 | "testing"
8 | )
9 |
10 | var testKey = "Margo the magpie"
11 |
12 | func TestClientSearch(t *testing.T) {
13 | torrent1 := Torrent{
14 | ID: "ID 1",
15 | Title: "Title 1",
16 | MagnetURI: "Magnet 1",
17 | SiteID: "test",
18 | Seeders: 10,
19 | Leechers: 100,
20 | Size: 123456,
21 | }
22 | torrent2 := Torrent{
23 | ID: "ID 2",
24 | Title: "Title 2",
25 | MagnetURI: "Magnet 2",
26 | SiteID: "test",
27 | Seeders: 20,
28 | Leechers: 200,
29 | Size: 654321,
30 | }
31 |
32 | var srvMethod, srvPath, srvQuery string
33 | var srvValid bool
34 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
35 | srvMethod = r.Method
36 | srvPath = r.URL.Path
37 | srvQuery = r.FormValue("q")
38 | srvValid = requestIsSigned(r, testKey)
39 | json.NewEncoder(w).Encode([]Torrent{torrent1, torrent2})
40 | }))
41 | defer srv.Close()
42 |
43 | var (
44 | expectedMethod = "GET"
45 | expectedPath = "/torrents"
46 | expectedQuery = "ubuntu 15.10"
47 | )
48 |
49 | ret := NewClient(srv.URL, testKey).Search(expectedQuery)
50 |
51 | if srvMethod != expectedMethod {
52 | t.Errorf("Search server method %q, expected %q", srvMethod, expectedMethod)
53 | }
54 | if srvPath != expectedPath {
55 | t.Errorf("Search server path %q, expected %q", srvPath, expectedPath)
56 | }
57 | if srvQuery != expectedQuery {
58 | t.Errorf("Search server query %q, expected %q", srvQuery, expectedQuery)
59 | }
60 | if !srvValid {
61 | t.Error("Search server request was not signed")
62 | }
63 |
64 | if l := ret.Length(); l != 2 {
65 | t.Fatalf("Search result length = %d, expected 2", l)
66 | }
67 |
68 | if trnt := ret.Get(0); *trnt != torrent1 {
69 | t.Errorf("Search result[0] = %v, expected %v", *trnt, torrent1)
70 | }
71 | if trnt := ret.Get(1); *trnt != torrent2 {
72 | t.Errorf("Search result[0] = %v, expected %v", *trnt, torrent2)
73 | }
74 | }
75 |
76 | func TestClientDownload(t *testing.T) {
77 | var (
78 | torrent = Torrent{ID: "someHash"}
79 |
80 | srvMethod, srvPath string
81 | srvValid bool
82 |
83 | expectedMethod = "POST"
84 | expectedPath = "/download/someHash"
85 | )
86 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
87 | srvMethod = r.Method
88 | srvPath = r.URL.Path
89 | srvValid = requestIsSigned(r, testKey)
90 | w.WriteHeader(http.StatusCreated)
91 | }))
92 | defer srv.Close()
93 |
94 | ret := NewClient(srv.URL, testKey).Download(&torrent)
95 |
96 | if srvMethod != expectedMethod {
97 | t.Errorf("Download server method %q, expected %q", srvMethod, expectedMethod)
98 | }
99 | if srvPath != expectedPath {
100 | t.Errorf("Download server path %q, expected %q", srvPath, expectedPath)
101 | }
102 | if !srvValid {
103 | t.Error("Download server request was not signed")
104 | }
105 |
106 | if ret != true {
107 | t.Errorf("Download result %v, expected %v", ret, true)
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/cmd/android/doc.go:
--------------------------------------------------------------------------------
1 | // Package android holds the native android client that talks to the server using go
2 | // bindings.
3 | package android
4 |
--------------------------------------------------------------------------------
/cmd/android/magopie/.gitignore:
--------------------------------------------------------------------------------
1 | # Default android studio ignores
2 | *.iml
3 | .gradle
4 | /local.properties
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .DS_Store
8 | /build
9 | /captures
10 |
11 | # Files for the dex VM
12 | *.dex
13 |
14 | # Java class files
15 | *.class
16 |
17 | # Generated files
18 | bin/
19 | gen/
20 |
21 | # gomobile generated files
22 | *.aar
23 |
24 | .idea/
25 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.bullercodeworks.magopie"
9 | minSdkVersion 15
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:22.1.1'
26 | compile project(':magopie-go')
27 | }
28 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/brbuller/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/androidTest/java/com/bullercodeworks/magopie/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.bullercodeworks.magopie;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/java/com/bullercodeworks/magopie/AboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.bullercodeworks.magopie;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class AboutActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_about);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/java/com/bullercodeworks/magopie/ConfigActivity.java:
--------------------------------------------------------------------------------
1 | package com.bullercodeworks.magopie;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.widget.EditText;
8 | import android.widget.TextView;
9 |
10 | /**
11 | * Created by brbuller on 1/23/16.
12 | */
13 | public class ConfigActivity extends Activity {
14 | public State state;
15 | EditText txtServerURL;
16 | EditText txtApiToken;
17 | Button btnSaveConfig;
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.content_config);
22 | state = new State();
23 | btnSaveConfig = (Button)findViewById(R.id.btnSaveConfig);
24 | txtServerURL = (EditText)findViewById(R.id.txtServerURL);
25 | txtApiToken = (EditText)findViewById(R.id.txtApiToken);
26 | btnSaveConfig.setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View view) {
29 | state.ServerURL = txtServerURL.getText().toString();
30 | state.ApiToken = txtApiToken.getText().toString();
31 |
32 | finish();
33 | }
34 | });
35 | }
36 |
37 | @Override
38 | public void onResume() {
39 | super.onResume();
40 | state.load();
41 | txtServerURL.setText(state.ServerURL);
42 | txtApiToken.setText(state.ApiToken);
43 | }
44 |
45 | @Override
46 | public void onPause() {
47 | state.save();
48 | super.onPause();
49 | }
50 |
51 | @Override
52 | public void onBackPressed() {
53 | if("".equals(txtServerURL.getText().toString())) {
54 | this.finishAffinity();
55 | } else {
56 | super.onBackPressed();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/java/com/bullercodeworks/magopie/State.java:
--------------------------------------------------------------------------------
1 | package com.bullercodeworks.magopie;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | import java.util.ArrayList;
7 | import java.util.HashMap;
8 |
9 | import go.magopie.Magopie;
10 |
11 | /**
12 | * Created by brbuller on 1/23/16.
13 | */
14 | public class State {
15 |
16 | public String file = "/data/data/com.bullercodeworks.magopie/state";
17 |
18 | public String ServerURL = "";
19 | public String ApiToken = "";
20 | public ArrayList results;
21 | public Magopie.Client client;
22 | public HashMap sites;
23 |
24 | public State() {
25 | load();
26 | results = new ArrayList<>();
27 | sites = new HashMap<>();
28 | client = Magopie.NewClient(ServerURL, ApiToken);
29 | Magopie.SiteCollection s = UpdateSites();
30 | for(int i = 0; i < s.Length(); i++) {
31 | sites.put(s.Get(i).getID(), s.Get(i).getName());
32 | }
33 | }
34 |
35 | public Magopie.SiteCollection UpdateSites() {
36 | return client.ListSites();
37 | }
38 |
39 | public void save() {
40 | try {
41 | JSONObject jsonState = new JSONObject();
42 | jsonState.put("serverURL", ServerURL);
43 | jsonState.put("apiToken", ApiToken);
44 | Magopie.SaveToFile(file, jsonState.toString().getBytes());
45 | } catch(Exception e) { }
46 | }
47 |
48 | public void load() {
49 | String ret = "";
50 | byte[] res = Magopie.ReadFromFile(file);
51 | if(res != null && res.length > 0) {
52 | ret = new String(res);
53 | try {
54 | JSONObject jsonState = new JSONObject(ret);
55 | ServerURL = jsonState.getString("serverURL");
56 | ApiToken = jsonState.getString("apiToken");
57 | } catch(JSONException e) {}
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-hdpi/magnet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-hdpi/magnet.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-hdpi/magopie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-hdpi/magopie.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-hdpi/magopie_android_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-hdpi/magopie_android_icon.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-hdpi/magopie_logo_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-hdpi/magopie_logo_text.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-ldpi/magnet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-ldpi/magnet.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-ldpi/magopie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-ldpi/magopie.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-ldpi/magopie_android_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-ldpi/magopie_android_icon.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-ldpi/magopie_logo_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-ldpi/magopie_logo_text.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-mdpi/magnet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-mdpi/magnet.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-mdpi/magopie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-mdpi/magopie.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-mdpi/magopie_android_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-mdpi/magopie_android_icon.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-mdpi/magopie_logo_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-mdpi/magopie_logo_text.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magnet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magnet.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magopie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magopie.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magopie_android_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magopie_android_icon.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magopie_logo_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xhdpi/magopie_logo_text.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magnet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magnet.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magopie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magopie.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magopie_android_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magopie_android_icon.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magopie_logo_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxhdpi/magopie_logo_text.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magnet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magnet.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magopie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magopie.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magopie_android_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magopie_android_icon.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magopie_logo_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/drawable-xxxhdpi/magopie_logo_text.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/layout/content_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
14 |
19 |
23 |
28 |
29 |
33 |
34 |
38 |
39 |
43 |
44 |
48 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
18 |
22 |
23 |
28 |
29 |
34 |
38 |
39 |
44 |
49 |
54 |
55 |
56 |
61 |
66 |
71 |
75 |
76 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/layout/torrent_list_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
15 |
16 |
21 |
22 |
28 |
29 |
35 |
36 |
41 |
48 |
49 |
54 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/menu/popup_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
8 |
9 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Magopie
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/cmd/android/magopie/app/src/test/java/com/bullercodeworks/magopie/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bullercodeworks.magopie;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/cmd/android/magopie/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/cmd/android/magopie/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/cmd/android/magopie/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/cmd/android/magopie/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/cmd/android/magopie/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/cmd/android/magopie/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/cmd/android/magopie/magopie-go/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "org.golang.mobile.bind" version "0.2.3"
3 | }
4 |
5 | gobind {
6 | pkg = "github.com/devict/magopie"
7 | }
8 |
--------------------------------------------------------------------------------
/cmd/android/magopie/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app',':magopie-go'
2 |
--------------------------------------------------------------------------------
/cmd/magopie-cui/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore Binary
2 | magopie-cui
--------------------------------------------------------------------------------
/cmd/magopie-cui/screen.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "github.com/nsf/termbox-go"
4 |
5 | type screen interface {
6 | handleKeyEvent(event termbox.Event) int
7 | performLayout(stl style)
8 | drawScreen(stl style)
9 | }
10 |
11 | const (
12 | searchScreenIndex = iota
13 | aboutScreenIndex
14 | exitScreenIndex
15 | )
16 |
17 | func defaultScreens() []screen {
18 | searchScreen := searchScreen{}
19 | aboutScreen := aboutScreen{}
20 | screens := []screen{
21 | &searchScreen,
22 | &aboutScreen,
23 | }
24 |
25 | return screens
26 | }
27 |
28 | func drawBackground(bg termbox.Attribute) {
29 | termbox.Clear(0, bg)
30 | }
31 |
32 | func layoutAndDrawScreen(screen screen, stl style) {
33 | screen.performLayout(stl)
34 | drawBackground(stl.defaultBg)
35 | screen.drawScreen(stl)
36 | termbox.Flush()
37 | }
38 |
39 | type style struct {
40 | defaultBg termbox.Attribute
41 | defaultFg termbox.Attribute
42 | titleFg termbox.Attribute
43 | titleBg termbox.Attribute
44 | cursorFg termbox.Attribute
45 | cursorBg termbox.Attribute
46 | }
47 |
48 | func defaultStyle() style {
49 | var stl style
50 | stl.defaultBg = termbox.ColorBlack
51 | stl.defaultFg = termbox.ColorWhite
52 | stl.titleFg = termbox.ColorBlack
53 | stl.titleBg = termbox.ColorGreen
54 | stl.cursorFg = termbox.ColorBlack
55 | stl.cursorBg = termbox.ColorGreen
56 |
57 | return stl
58 | }
59 |
60 | type cursor struct {
61 | x int
62 | y int
63 | }
64 |
--------------------------------------------------------------------------------
/cmd/magopie-cui/screen_about.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/br0xen/termbox-util"
7 | "github.com/nsf/termbox-go"
8 | )
9 |
10 | type command struct {
11 | key string
12 | description string
13 | }
14 |
15 | type aboutScreen struct {
16 | initialized bool
17 | col1Commands []command
18 | col2Commands []command
19 | titleArt *termboxUtil.ASCIIArt
20 | }
21 |
22 | func drawCommandsAtPoint(commands []command, x int, y int, stl style) {
23 | xPos, yPos := x, y
24 | for index, cmd := range commands {
25 | termboxUtil.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), xPos, yPos, stl.defaultFg, stl.defaultBg)
26 | termboxUtil.DrawStringAtPoint(cmd.description, xPos+8, yPos, stl.defaultFg, stl.defaultBg)
27 | yPos++
28 | if index > 2 && index%2 == 1 {
29 | yPos++
30 | }
31 | }
32 | }
33 |
34 | func (screen *aboutScreen) handleKeyEvent(event termbox.Event) int {
35 | return searchScreenIndex
36 | }
37 |
38 | func (screen *aboutScreen) performLayout(stl style) {
39 | if !screen.initialized {
40 | width, _ := termbox.Size()
41 | var template []string
42 | template = append(template, " _ ")
43 | template = append(template, " (_) ")
44 | template = append(template, " _ __ ___ __ _ __ _ ___ _ __ _ ___ ")
45 | template = append(template, "| '_ ` _ \\ / _` |/ _` |/ _ \\| '_ \\| |/ _ \\")
46 | template = append(template, "| | | | | | (_| | (_| | (_) | |_) | | __/")
47 | template = append(template, "|_| |_| |_|\\__,_|\\__, |\\___/| .__/|_|\\___|")
48 | template = append(template, " __/ | | | ")
49 | template = append(template, " |___/ |_| ")
50 | startX := (width - len(template[0])) / 2
51 | startY := 1
52 |
53 | screen.titleArt = termboxUtil.CreateASCIIArt(template, startX, startY, stl.defaultFg, stl.defaultBg)
54 |
55 | screen.col1Commands = append(screen.col1Commands, command{"j,↓", "down"})
56 | screen.col1Commands = append(screen.col1Commands, command{"k,↑", "up"})
57 | screen.col1Commands = append(screen.col1Commands, command{"", ""})
58 | screen.col1Commands = append(screen.col1Commands, command{"", "trigger download"})
59 |
60 | screen.col2Commands = append(screen.col2Commands, command{"ctrl+s", "save config"})
61 | screen.col2Commands = append(screen.col2Commands, command{"ctrl+q", "jump up"})
62 | screen.col2Commands = append(screen.col2Commands, command{"ctrl+h", "this screen"})
63 | }
64 | screen.initialized = true
65 | }
66 |
67 | func (screen *aboutScreen) drawScreen(stl style) {
68 | width, height := termbox.Size()
69 | defaultFg := stl.defaultFg
70 | defaultBg := stl.defaultBg
71 |
72 | screen.titleArt.Draw()
73 |
74 | xPos := screen.titleArt.GetX()
75 | yPos := screen.titleArt.GetY() + screen.titleArt.GetHeight() + 1
76 |
77 | tabTxt := " switch between search and results"
78 | termboxUtil.DrawStringAtPoint(tabTxt, (width-len(tabTxt))/2, yPos, defaultFg, defaultBg)
79 | yPos++
80 | drawCommandsAtPoint(screen.col1Commands, xPos-5, yPos+1, stl)
81 | drawCommandsAtPoint(screen.col2Commands, xPos+30, yPos+1, stl)
82 | exitTxt := "Press any key to return to search"
83 | termboxUtil.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, stl.titleFg, stl.titleBg)
84 | }
85 |
--------------------------------------------------------------------------------
/cmd/magopie/.gitignore:
--------------------------------------------------------------------------------
1 | magopie
2 | *.swp
3 |
--------------------------------------------------------------------------------
/cmd/magopie/doc.go:
--------------------------------------------------------------------------------
1 | // The magopie server aggregates search results from various torrent sites
2 | // and downloads specified torrent files.
3 | //
4 | // Available routes are:
5 | //
6 | // GET /sites
7 | // GET /sites/{id}
8 | //*POST /sites/{id}/enabled
9 | //*DELETE /sites/{id}/enabled
10 |
11 | // GET /torrents?q=ubuntu
12 | // POST /download/{id}
13 | package main
14 |
--------------------------------------------------------------------------------
/cmd/magopie/errors.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "errors"
4 |
5 | var (
6 | // ErrFailedRequest is returned when we get a non-200 status from one of our
7 | // upstream sites.
8 | ErrFailedRequest = errors.New("http request had non-200 status")
9 |
10 | // ErrHashlessMagnet is returned when we fail to parse the BTIH hash from a
11 | // Magnet URI
12 | ErrHashlessMagnet = errors.New("could not find hash in magnet URI")
13 |
14 | // ErrCannotFindFileSize is used when we fail to parse the file size for a
15 | // torrent returned from TPB.
16 | ErrCannotFindFileSize = errors.New("could not find tpb filesize in html")
17 | )
18 |
--------------------------------------------------------------------------------
/cmd/magopie/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "flag"
5 | "fmt"
6 | "log"
7 | "net/http"
8 | "os"
9 |
10 | "github.com/devict/magopie"
11 | "github.com/gorilla/mux"
12 | "github.com/justinas/alice"
13 | "github.com/spf13/afero"
14 | )
15 |
16 | var (
17 | addr = flag.String("addr", ":8080", "HTTP(S) service address")
18 | downloadDir = flag.String("dir", ".", "Directory where magopie should download .torrent files")
19 | apiKey = flag.String("key", "", "Shared API key for clients (required)")
20 | tlsKey = flag.String("tlsKey", "", "Path to TLS Key")
21 | tlsCert = flag.String("tlsCert", "", "Path to TLS Cert")
22 | )
23 |
24 | func init() {
25 | log.SetFlags(log.LstdFlags | log.Lshortfile)
26 | }
27 |
28 | func main() {
29 | flag.Parse()
30 |
31 | if *apiKey == "" {
32 | fmt.Fprintln(os.Stderr, "-key flag is required")
33 | flag.Usage()
34 | os.Exit(1)
35 | }
36 |
37 | a := &server{
38 | key: *apiKey,
39 | fs: afero.OsFs{},
40 | sites: sitedb{
41 | sites: []site{
42 | kickAssTorrents,
43 | thePirateBay,
44 | },
45 | },
46 | torcacheURL: "http://torcache.net",
47 | downloadDir: *downloadDir,
48 | }
49 |
50 | if *tlsKey != "" && *tlsCert != "" {
51 | log.Printf("Listening for HTTPS on %s with key %s and cert %s", *addr, *tlsKey, *tlsCert)
52 | log.Fatal(http.ListenAndServeTLS(*addr, *tlsCert, *tlsKey, router(a)))
53 | } else {
54 | log.Printf("Listening for HTTP on %s", *addr)
55 | log.Fatal(http.ListenAndServe(*addr, router(a)))
56 | }
57 | }
58 |
59 | func router(a *server) http.Handler {
60 | r := mux.NewRouter()
61 |
62 | r.HandleFunc("/sites", a.handleAllSites).Methods("GET")
63 | r.HandleFunc("/sites/{id}", a.handleSingleSite).Methods("GET")
64 | r.HandleFunc("/torrents", a.handleTorrents).Methods("GET")
65 | r.HandleFunc("/download/{hash}", a.handleDownload).Methods("POST")
66 |
67 | chain := alice.New(mwLogger, mwAuthenticationCheck(a.key)).Then(r)
68 |
69 | return chain
70 | }
71 |
72 | func mwLogger(next http.Handler) http.Handler {
73 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
74 | log.Println("Serving", r.Method, r.URL.String(), "to", r.RemoteAddr)
75 | next.ServeHTTP(w, r)
76 | })
77 | }
78 |
79 | func mwAuthenticationCheck(key string) func(http.Handler) http.Handler {
80 | return func(next http.Handler) http.Handler {
81 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
82 | if !magopie.CheckMAC(r.Header.Get("X-Request-ID"), r.Header.Get("X-HMAC"), key) {
83 | log.Println("Request failed HMAC")
84 | w.WriteHeader(http.StatusUnauthorized)
85 | return
86 | }
87 | next.ServeHTTP(w, r)
88 | })
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/cmd/magopie/site_kat.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/xml"
5 | "fmt"
6 | "io"
7 | "net/http"
8 | "net/url"
9 |
10 | "github.com/devict/magopie"
11 | )
12 |
13 | var kickAssTorrents = site{
14 | Site: magopie.Site{
15 | ID: "kat",
16 | Name: "Kick Ass Torrents",
17 | URL: "https://kat.ph",
18 | Enabled: true,
19 | },
20 | search: func(term string) ([]magopie.Torrent, error) {
21 | url := fmt.Sprintf(
22 | "https://kat.cr/usearch/%s/?rss=1",
23 | url.QueryEscape(term),
24 | )
25 |
26 | res, err := http.DefaultClient.Get(url)
27 | if err != nil {
28 | return nil, err
29 | }
30 | defer res.Body.Close()
31 |
32 | if res.StatusCode != 200 {
33 | return nil, ErrFailedRequest
34 | }
35 |
36 | return katParse(res.Body)
37 | },
38 | }
39 |
40 | func katParse(r io.Reader) ([]magopie.Torrent, error) {
41 | var d struct {
42 | Items []struct {
43 | Title string `xml:"title"`
44 | ContentLength int `xml:"contentLength"`
45 | Hash string `xml:"infoHash"`
46 | Seeds int `xml:"seeds"`
47 | Peers int `xml:"peers"`
48 | MagnetURI string `xml:"magnetURI"`
49 | } `xml:"channel>item"`
50 | }
51 |
52 | if err := xml.NewDecoder(r).Decode(&d); err != nil {
53 | return nil, err
54 | }
55 |
56 | ts := make([]magopie.Torrent, len(d.Items))
57 | for i, item := range d.Items {
58 | ts[i] = magopie.Torrent{
59 | ID: item.Hash,
60 | Title: item.Title,
61 | Seeders: item.Seeds,
62 | Leechers: item.Peers - item.Seeds,
63 | Size: item.ContentLength,
64 | MagnetURI: item.MagnetURI,
65 | SiteID: "kat",
66 | }
67 | }
68 |
69 | return ts, nil
70 | }
71 |
--------------------------------------------------------------------------------
/cmd/magopie/site_kat_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "os"
5 | "reflect"
6 | "testing"
7 |
8 | mp "github.com/devict/magopie"
9 | )
10 |
11 | func TestKATParse(t *testing.T) {
12 | data, err := os.Open("testdata/kat_ubuntu.xml")
13 | if err != nil {
14 | t.Fatal("Error opening fixture", err)
15 | }
16 | defer data.Close()
17 |
18 | actual, err := katParse(data)
19 | if err != nil {
20 | t.Fatal("katParse err should be nil, was:", err)
21 | }
22 |
23 | expected := []mp.Torrent{
24 | {
25 | ID: "0C5B427C2F833B09EA0E3DC7C624F6C187125267",
26 | Title: "Ubuntu Linux Go from Beginner to Power User!",
27 | MagnetURI: "magnet:?xt=urn:btih:0C5B427C2F833B09EA0E3DC7C624F6C187125267&dn=ubuntu+linux+go+from+beginner+to+power+user&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce",
28 | SiteID: "kat",
29 | Size: 1137244499,
30 | Seeders: 85,
31 | Leechers: 105,
32 | },
33 | {
34 | ID: "21236117B7A773639BD5C7C771E66A045BD51A8A",
35 | Title: "Learning Ubuntu Linux Server",
36 | MagnetURI: "magnet:?xt=urn:btih:21236117B7A773639BD5C7C771E66A045BD51A8A&dn=learning+ubuntu+linux+server&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce",
37 | SiteID: "kat",
38 | Size: 581653341,
39 | Seeders: 48,
40 | Leechers: 12,
41 | },
42 | {
43 | ID: "13DBA979D53F20E6A73D4EE939952D1C367B64C7",
44 | Title: "CodeWeavers Crossover 15.0.1 with crack for ubuntu fedora linux",
45 | MagnetURI: "magnet:?xt=urn:btih:13DBA979D53F20E6A73D4EE939952D1C367B64C7&dn=codeweavers+crossover+15+0+1+with+crack+for+ubuntu+fedora+linux&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce",
46 | SiteID: "kat",
47 | Size: 240330669,
48 | Seeders: 1,
49 | Leechers: 1,
50 | },
51 | {
52 | ID: "EB7B040141407F150E32FF366CD624403387B5C1",
53 | Title: "Ubuntu 16.04 (Xenial Xerus) Alpha Desktop AMD64 (64-bit PC)",
54 | MagnetURI: "magnet:?xt=urn:btih:EB7B040141407F150E32FF366CD624403387B5C1&dn=ubuntu+16+04+xenial+xerus+alpha+desktop+amd64+64+bit+pc&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce",
55 | SiteID: "kat",
56 | Size: 1480048640,
57 | Seeders: 1,
58 | Leechers: 3,
59 | },
60 | }
61 |
62 | if !reflect.DeepEqual(actual, expected) {
63 | t.Errorf("tpbParse actual = %v\nexpected %v", actual, expected)
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/cmd/magopie/site_tpb.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "io"
6 | "log"
7 | "net/http"
8 | "net/url"
9 | "regexp"
10 | "strconv"
11 |
12 | "github.com/PuerkitoBio/goquery"
13 | "github.com/devict/magopie"
14 | "github.com/dustin/go-humanize"
15 | )
16 |
17 | var thePirateBay = site{
18 | Site: magopie.Site{
19 | ID: "tpb",
20 | Name: "The Pirate Bay",
21 | URL: "https://thepiratebay.se",
22 | Enabled: true,
23 | },
24 | search: func(term string) ([]magopie.Torrent, error) {
25 | url := fmt.Sprintf(
26 | "https://thepiratebay.se/search/%s/0/7/0",
27 | url.QueryEscape(term),
28 | )
29 |
30 | res, err := http.DefaultClient.Get(url)
31 | if err != nil {
32 | return nil, err
33 | }
34 | defer res.Body.Close()
35 |
36 | if res.StatusCode != 200 {
37 | return nil, ErrFailedRequest
38 | }
39 |
40 | return tpbParse(res.Body)
41 | },
42 | }
43 |
44 | func tpbParse(r io.Reader) ([]magopie.Torrent, error) {
45 | doc, err := goquery.NewDocumentFromReader(r)
46 | if err != nil {
47 | return nil, err
48 | }
49 |
50 | var torrents []magopie.Torrent
51 | doc.Find("table#searchResult tr").Each(func(i int, s *goquery.Selection) {
52 | // First child is header row
53 | if i <= 0 {
54 | return
55 | }
56 |
57 | magnet, ok := s.Find("div.detName + a").Attr("href")
58 | if !ok {
59 | return
60 | }
61 |
62 | // hash gets ripped from magnet
63 | hash, err := hashFromMagnet(magnet)
64 | if err != nil {
65 | log.Print(err)
66 | return
67 | }
68 |
69 | seed, err := strconv.Atoi(s.Children().Eq(2).Text())
70 | if err != nil {
71 | log.Print(err)
72 | seed = 0
73 | }
74 |
75 | leech, err := strconv.Atoi(s.Children().Eq(3).Text())
76 | if err != nil {
77 | log.Print(err)
78 | leech = 0
79 | }
80 |
81 | // Need to rip human-friendly filesize from description and make it ugly
82 | details := s.Find("font.detDesc").Text()
83 | size, err := bytesFromDetails(details)
84 | if err != nil {
85 | log.Print(err)
86 | size = 0
87 | }
88 |
89 | t := magopie.Torrent{
90 | ID: hash,
91 | Title: s.Find("div.detName a").Text(),
92 | MagnetURI: magnet,
93 | SiteID: "tpb",
94 | Seeders: seed,
95 | Leechers: leech,
96 | Size: size,
97 | }
98 |
99 | torrents = append(torrents, t)
100 | })
101 |
102 | return torrents, nil
103 | }
104 |
105 | // btihRE finds the BTIH hash from the xt segment of a Magnet URI
106 | var btihRE = regexp.MustCompile(`urn:btih:(.+)`)
107 |
108 | func hashFromMagnet(m string) (string, error) {
109 | parsed, err := url.Parse(m)
110 | if err != nil {
111 | return "", err
112 | }
113 |
114 | matches := btihRE.FindStringSubmatch(parsed.Query().Get("xt"))
115 | if len(matches) <= 0 {
116 | return "", ErrHashlessMagnet
117 | }
118 |
119 | return matches[1], nil
120 | }
121 |
122 | func bytesFromDetails(d string) (int, error) {
123 | re := regexp.MustCompile(`, Size ([^,]+)`)
124 | match := re.FindStringSubmatch(d)
125 |
126 | if len(match) <= 0 {
127 | return 0, ErrCannotFindFileSize
128 | }
129 |
130 | bytes, err := humanize.ParseBigBytes(match[1])
131 | if err != nil {
132 | log.Print(err)
133 | return 0, err
134 | }
135 |
136 | return int(bytes.Int64()), nil
137 | }
138 |
--------------------------------------------------------------------------------
/cmd/magopie/site_tpb_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "os"
5 | "reflect"
6 | "testing"
7 |
8 | mp "github.com/devict/magopie"
9 | )
10 |
11 | func TestTPBParse(t *testing.T) {
12 | data, err := os.Open("testdata/tpb_ubuntu")
13 | if err != nil {
14 | t.Fatal("Error opening fixture", err)
15 | }
16 | defer data.Close()
17 |
18 | actual, err := tpbParse(data)
19 | if err != nil {
20 | t.Fatal("tpbParse err should be nil, was:", err)
21 | }
22 |
23 | expected := []mp.Torrent{
24 | {
25 | ID: "1619ecc9373c3639f4ee3e261638f29b33a6cbd6",
26 | Title: "Ubuntu 14.10 i386 (Desktop ISO)",
27 | MagnetURI: "magnet:?xt=urn:btih:1619ecc9373c3639f4ee3e261638f29b33a6cbd6&dn=Ubuntu+14.10+i386+%28Desktop+ISO%29&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
28 | SiteID: "tpb",
29 | Seeders: 66,
30 | Leechers: 8,
31 | Size: 1191853424,
32 | },
33 | {
34 | ID: "4896fde14efbc0f66a274d2a69104fbb57fbd2cb",
35 | Title: "Ubuntu 15.04 Desktop i386, [Iso - MultiLang] [TNTVillage]",
36 | MagnetURI: "magnet:?xt=urn:btih:4896fde14efbc0f66a274d2a69104fbb57fbd2cb&dn=Ubuntu+15.04+Desktop+i386%2C+%5BIso+-+MultiLang%5D+%5BTNTVillage%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
37 | SiteID: "tpb",
38 | Seeders: 33,
39 | Leechers: 3,
40 | Size: 1191853424,
41 | },
42 | {
43 | ID: "b415c913643e5ff49fe37d304bbb5e6e11ad5101",
44 | Title: "Ubuntu 14.10 desktop x64",
45 | MagnetURI: "magnet:?xt=urn:btih:b415c913643e5ff49fe37d304bbb5e6e11ad5101&dn=Ubuntu+14.10+desktop++x64&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
46 | SiteID: "tpb",
47 | Seeders: 23,
48 | Leechers: 1,
49 | Size: 1159641169,
50 | },
51 | }
52 |
53 | if !reflect.DeepEqual(actual, expected) {
54 | t.Errorf("tpbParse actual = %v\nexpected %v", actual, expected)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/cmd/magopie/sitedb.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "sync"
5 |
6 | "github.com/devict/magopie"
7 | )
8 |
9 | type site struct {
10 | magopie.Site
11 | search func(term string) ([]magopie.Torrent, error)
12 | }
13 |
14 | type sitedb struct {
15 | mtx sync.RWMutex
16 | sites []site
17 | }
18 |
19 | func (db *sitedb) GetSite(id string) site {
20 | db.mtx.RLock()
21 | defer db.mtx.RUnlock()
22 |
23 | for _, s := range db.sites {
24 | if s.ID == id {
25 | return s
26 | }
27 | }
28 |
29 | return site{}
30 | }
31 |
32 | func (db *sitedb) GetAllSites() []site {
33 | db.mtx.RLock()
34 | defer db.mtx.RUnlock()
35 |
36 | return db.sites
37 | }
38 |
39 | func (db *sitedb) GetEnabledSites() []site {
40 | db.mtx.RLock()
41 | defer db.mtx.RUnlock()
42 |
43 | var sites []site
44 | for _, s := range db.sites {
45 | if s.Enabled {
46 | sites = append(sites, s)
47 | }
48 | }
49 | return sites
50 | }
51 |
--------------------------------------------------------------------------------
/cmd/magopie/sitedb_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "reflect"
5 | "testing"
6 |
7 | mp "github.com/devict/magopie"
8 | )
9 |
10 | var (
11 | siteFoo = site{Site: mp.Site{ID: "foo", Enabled: true}}
12 | siteBar = site{Site: mp.Site{ID: "bar", Enabled: false}}
13 | siteBaz = site{Site: mp.Site{ID: "baz", Enabled: true}}
14 | )
15 |
16 | func TestGetSite(t *testing.T) {
17 | a := sitedb{
18 | sites: []site{siteFoo, siteBar},
19 | }
20 |
21 | if actual := a.GetSite(siteBar.ID); !reflect.DeepEqual(actual, siteBar) {
22 | t.Errorf("sitedb.GetSite(%q) = %v, expected %v", siteBar.ID, actual, siteBar)
23 | }
24 | }
25 |
26 | func TestGetAllSites(t *testing.T) {
27 | a := sitedb{
28 | sites: []site{siteFoo, siteBar, siteBaz},
29 | }
30 |
31 | expected := []site{siteFoo, siteBar, siteBaz}
32 | if actual := a.GetAllSites(); !reflect.DeepEqual(actual, expected) {
33 | t.Errorf("sitedb.GetAllSites() = %v, expected %v", actual, expected)
34 | }
35 | }
36 |
37 | func TestGetEnabledSites(t *testing.T) {
38 | a := sitedb{
39 | sites: []site{siteFoo, siteBar, siteBaz},
40 | }
41 |
42 | expected := []site{siteFoo, siteBaz}
43 | if actual := a.GetEnabledSites(); !reflect.DeepEqual(actual, expected) {
44 | t.Errorf("sitedb.GetAllSites() = %v, expected %v", actual, siteBar)
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/cmd/magopie/test_helpers_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "io"
5 | "net/http"
6 | "testing"
7 |
8 | "github.com/devict/magopie"
9 | "github.com/pborman/uuid"
10 | )
11 |
12 | var testKey = "Margo the magpie"
13 |
14 | func mustNewRequest(t *testing.T, method, urlStr string, body io.Reader) *http.Request {
15 | r, err := http.NewRequest(method, urlStr, body)
16 | if err != nil {
17 | t.Fatal(err)
18 | }
19 |
20 | id := uuid.NewRandom().String()
21 | r.Header.Set("X-Request-ID", id)
22 | r.Header.Set("X-HMAC", magopie.HMAC(id, testKey))
23 |
24 | return r
25 | }
26 |
27 | func describeReq(req *http.Request) string {
28 | return req.Method + " " + req.URL.String()
29 | }
30 |
31 | func diffMaps(t *testing.T, a, b []map[string]interface{}) {
32 | for i := range a {
33 | for k := range a[i] {
34 | valA, valB := a[i][k], b[i][k]
35 | if valA != valB {
36 | t.Logf("%d %q: a: %v, b: %v", i, k, valA, valB)
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/doc.go:
--------------------------------------------------------------------------------
1 | // package magopie client libs for interfacing with a magopie personal torrent
2 | // search engine server.
3 |
4 | package magopie
5 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/logo.png
--------------------------------------------------------------------------------
/margo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devict/magopie/509f4724787d7f1d8ac76e7344fb5acb7b9d39b0/margo.png
--------------------------------------------------------------------------------
/site.go:
--------------------------------------------------------------------------------
1 | package magopie
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | )
7 |
8 | // Site defines a site that serves torrent files.
9 | type Site struct {
10 | ID string
11 | Name string
12 | URL string
13 | Enabled bool
14 | }
15 |
16 | // SiteCollection is a collection of sites because gomobile can't
17 | // handle slices
18 | type SiteCollection struct {
19 | list []Site
20 | }
21 |
22 | // Length returns how many sites are in the collection
23 | func (sc *SiteCollection) Length() int {
24 | return len(sc.list)
25 | }
26 |
27 | // Get returns the site at idx or a nil site
28 | func (sc *SiteCollection) Get(idx int) *Site {
29 | if idx <= sc.Length() {
30 | return &sc.list[idx]
31 | }
32 | return nil
33 | }
34 |
35 | // Clear empties the list of sites
36 | func (sc *SiteCollection) Clear() {
37 | sc.list = sc.list[:0]
38 | }
39 |
40 | // Index finds the index of a site or -1 if not found
41 | func (sc *SiteCollection) Index(s *Site) int {
42 | for i, tst := range sc.list {
43 | if tst == *s {
44 | return i
45 | }
46 | }
47 | return -1
48 | }
49 |
50 | // Insert inserts a site into the collection at i
51 | func (sc *SiteCollection) Insert(i int, s *Site) {
52 | if i < 0 || i > sc.Length() {
53 | fmt.Printf("Magopie-go:: Attempted to insert a site at an invalid index")
54 | return
55 | }
56 | sc.list = append(sc.list, Site{})
57 | copy(sc.list[i+1:], sc.list[i:])
58 | sc.list[i] = *s
59 | }
60 |
61 | // Remove a site from the collection at i
62 | func (sc *SiteCollection) Remove(i int) {
63 | if i < 0 || i > sc.Length() {
64 | fmt.Printf("Magopie-go:: Attempted to remove a site from an invalid index")
65 | return
66 | }
67 | copy(sc.list[i:], sc.list[i+1:])
68 | sc.list[len(sc.list)-1] = Site{}
69 | sc.list = sc.list[:len(sc.list)-1]
70 | }
71 |
72 | // Push adds an element to the end of the collection
73 | func (sc *SiteCollection) Push(s *Site) {
74 | sc.Insert(sc.Length(), s)
75 | }
76 |
77 | // Pop removes the last element from the collection
78 | func (sc *SiteCollection) Pop(s *Site) {
79 | sc.Remove(sc.Length() - 1)
80 | }
81 |
82 | // Unshift adds an element to the front of the collection
83 | func (sc *SiteCollection) Unshift(s *Site) {
84 | sc.Insert(0, s)
85 | }
86 |
87 | // Shift removes an element from the front of the collection
88 | func (sc *SiteCollection) Shift(s *Site) {
89 | sc.Remove(0)
90 | }
91 |
92 | // MarshalJSON returns JSON from the collection
93 | func (sc *SiteCollection) MarshalJSON() ([]byte, error) {
94 | return json.Marshal(sc.list)
95 | }
96 |
97 | // UnmarshalJSON replaces the collection with the results from a JSON []byte
98 | func (sc *SiteCollection) UnmarshalJSON(data []byte) error {
99 | return json.Unmarshal(data, &sc.list)
100 | }
101 |
--------------------------------------------------------------------------------
/torrent.go:
--------------------------------------------------------------------------------
1 | package magopie
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | )
7 |
8 | // A Torrent is an individual result from a search operation representing a
9 | // single torrent file.
10 | type Torrent struct {
11 | ID string
12 | Title string
13 | MagnetURI string
14 | SiteID string
15 | Seeders int
16 | Leechers int
17 | Size int
18 | }
19 |
20 | // TorrentCollection is a collection of torrents because gomobile can't
21 | // handle slices
22 | type TorrentCollection struct {
23 | list []Torrent
24 | }
25 |
26 | // Length returns how many torrents are in the collection
27 | func (tc *TorrentCollection) Length() int {
28 | return len(tc.list)
29 | }
30 |
31 | // Get returns the torrent at idx or a nil torrent
32 | func (tc *TorrentCollection) Get(idx int) *Torrent {
33 | if idx <= tc.Length() {
34 | return &tc.list[idx]
35 | }
36 | return nil
37 | }
38 |
39 | // Clear empties the list of torrents
40 | func (tc *TorrentCollection) Clear() {
41 | tc.list = tc.list[:0]
42 | }
43 |
44 | // Index finds the index of a torrent or -1 if not found
45 | func (tc *TorrentCollection) Index(t *Torrent) int {
46 | for i, tst := range tc.list {
47 | if tst == *t {
48 | return i
49 | }
50 | }
51 | return -1
52 | }
53 |
54 | // Insert inserts a torrent into the collection at i
55 | func (tc *TorrentCollection) Insert(i int, t *Torrent) {
56 | if i < 0 || i > tc.Length() {
57 | fmt.Printf("Magopie-go:: Attempted to insert a torrent at an invalid index")
58 | return
59 | }
60 | tc.list = append(tc.list, Torrent{})
61 | copy(tc.list[i+1:], tc.list[i:])
62 | tc.list[i] = *t
63 | }
64 |
65 | // Remove a torrent from the collection at i
66 | func (tc *TorrentCollection) Remove(i int) {
67 | if i < 0 || i >= tc.Length() {
68 | fmt.Printf("Magopie-go:: Attempted to remove a torrent from an invalid index")
69 | return
70 | }
71 | copy(tc.list[i:], tc.list[i+1:])
72 | tc.list[len(tc.list)-1] = Torrent{}
73 | tc.list = tc.list[:len(tc.list)-1]
74 | }
75 |
76 | // Push adds an element to the end of the collection
77 | func (tc *TorrentCollection) Push(t *Torrent) {
78 | tc.Insert(tc.Length(), t)
79 | }
80 |
81 | // Pop removes the last element from the collection
82 | func (tc *TorrentCollection) Pop(t *Torrent) {
83 | tc.Remove(tc.Length() - 1)
84 | }
85 |
86 | // Unshift adds an element to the front of the collection
87 | func (tc *TorrentCollection) Unshift(t *Torrent) {
88 | tc.Insert(0, t)
89 | }
90 |
91 | // Shift removes an element from the front of the collection
92 | func (tc *TorrentCollection) Shift(t *Torrent) {
93 | tc.Remove(0)
94 | }
95 |
96 | // MarshalJSON returns JSON from the collection
97 | func (tc *TorrentCollection) MarshalJSON() ([]byte, error) {
98 | return json.Marshal(tc.list)
99 | }
100 |
101 | // UnmarshalJSON replaces the collection with the results from a JSON []byte
102 | func (tc *TorrentCollection) UnmarshalJSON(data []byte) error {
103 | return json.Unmarshal(data, &tc.list)
104 | }
105 |
--------------------------------------------------------------------------------
/util.go:
--------------------------------------------------------------------------------
1 | package magopie
2 |
3 | import (
4 | "crypto/hmac"
5 | "crypto/sha256"
6 | "encoding/hex"
7 | "fmt"
8 | "io/ioutil"
9 | "log"
10 | "net/http"
11 |
12 | "github.com/pborman/uuid"
13 | )
14 |
15 | // SaveToFile saves 'data' to the file 'filePath'
16 | func SaveToFile(filePath string, data []byte) error {
17 | return ioutil.WriteFile(filePath, data, 0644)
18 | }
19 |
20 | // ReadFromFile returns the bytes from 'filePath'
21 | func ReadFromFile(filePath string) []byte {
22 | var data []byte
23 | var err error
24 | if data, err = ioutil.ReadFile(filePath); err != nil {
25 | fmt.Println(err)
26 | }
27 | return data
28 | }
29 |
30 | // HMAC gives the sha256 HMAC of message using key. It is expressed as a hex
31 | // string.
32 | func HMAC(message, key string) string {
33 | mac := hmac.New(sha256.New, []byte(key))
34 | mac.Write([]byte(message))
35 |
36 | return hex.EncodeToString(mac.Sum(nil))
37 | }
38 |
39 | // CheckMAC confirms that the mac provided with a message was signed with the
40 | // appropriate key. The mac should be in a hex string.
41 | func CheckMAC(message, messageMAC, key string) bool {
42 | msgMAC, err := hex.DecodeString(messageMAC)
43 | if err != nil {
44 | log.Print("message mac was not valid hex", err)
45 | return false
46 | }
47 |
48 | mac := hmac.New(sha256.New, []byte(key))
49 | mac.Write([]byte(message))
50 |
51 | return hmac.Equal(msgMAC, mac.Sum(nil))
52 | }
53 |
54 | // signRequest sets X-Request-ID and X-HMAC headers on a request signed with
55 | // the given key.
56 | func signRequest(r *http.Request, key string) {
57 | id := uuid.NewRandom().String()
58 | r.Header.Set("X-Request-ID", id)
59 | r.Header.Set("X-HMAC", HMAC(id, key))
60 | }
61 |
62 | // requestIsSigned validates the authentication headers on a request.
63 | func requestIsSigned(r *http.Request, key string) bool {
64 | hdr := r.Header
65 | return CheckMAC(hdr.Get("X-Request-ID"), hdr.Get("X-HMAC"), key)
66 | }
67 |
--------------------------------------------------------------------------------
/util_test.go:
--------------------------------------------------------------------------------
1 | package magopie
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 | )
7 |
8 | func TestHMAC(t *testing.T) {
9 | var (
10 | message = "hello"
11 | key = "world"
12 | mac = "3cfa76ef14937c1c0ea519f8fc057a80fcd04a7420f8e8bcd0a7567c272e007b"
13 | badMAC = "3cfa76ef14937c1c0ea519f8fc057a80fcd04a7420f8e8bcd0a7567c272e007c"
14 | )
15 |
16 | actual := HMAC(message, key)
17 |
18 | if actual != mac {
19 | t.Errorf("HMAC(%q, %q) = %q, expected %q", message, key, actual, mac)
20 | }
21 | if same := CheckMAC(message, mac, key); !same {
22 | t.Error("CheckMAC failed: returned false for known good MAC")
23 | }
24 | if same := CheckMAC(message, badMAC, key); same {
25 | t.Error("CheckMAC should have failed: returned true for bad MAC")
26 | }
27 | }
28 |
29 | func TestSignRequest(t *testing.T) {
30 | var (
31 | req, _ = http.NewRequest("GET", "/foo", nil)
32 | key = "banana"
33 | )
34 |
35 | signRequest(req, key)
36 |
37 | id := req.Header.Get("X-Request-ID")
38 | if id == "" {
39 | t.Fatal("Request header X-Request-ID was blank")
40 | }
41 |
42 | hmac := req.Header.Get("X-HMAC")
43 | if hmac == "" {
44 | t.Fatal("Request header X-HMAC was blank")
45 | }
46 |
47 | if !CheckMAC(id, hmac, key) {
48 | t.Fatal("Request X-HMAC was invalid")
49 | }
50 | }
51 |
52 | func TestRequestIsSigned(t *testing.T) {
53 | var (
54 | req, _ = http.NewRequest("GET", "/foo", nil)
55 | id = "hello"
56 | key = "world"
57 | mac = "3cfa76ef14937c1c0ea519f8fc057a80fcd04a7420f8e8bcd0a7567c272e007b"
58 | badMAC = "4cfa76ef14937c1c0ea519f8fc057a80fcd04a7420f8e8bcd0a7567c272e007b"
59 | )
60 |
61 | req.Header.Set("X-Request-ID", id)
62 | req.Header.Set("X-HMAC", mac)
63 |
64 | if !requestIsSigned(req, key) {
65 | t.Fatal("RequestIsSigned rejected our message, should have accepted it.")
66 | }
67 |
68 | req.Header.Set("X-HMAC", badMAC)
69 | if requestIsSigned(req, key) {
70 | t.Fatal("RequestIsSigned accepted our message, should have rejected it.")
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/vendor/github.com/PuerkitoBio/goquery/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012-2014, Martin Angers & Contributors
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 |
6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 |
8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 |
10 | * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 |
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13 |
--------------------------------------------------------------------------------
/vendor/github.com/PuerkitoBio/goquery/expand.go:
--------------------------------------------------------------------------------
1 | package goquery
2 |
3 | import (
4 | "github.com/andybalholm/cascadia"
5 | "golang.org/x/net/html"
6 | )
7 |
8 | // Add adds the selector string's matching nodes to those in the current
9 | // selection and returns a new Selection object.
10 | // The selector string is run in the context of the document of the current
11 | // Selection object.
12 | func (s *Selection) Add(selector string) *Selection {
13 | return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, cascadia.MustCompile(selector))...)
14 | }
15 |
16 | // AddMatcher adds the matcher's matching nodes to those in the current
17 | // selection and returns a new Selection object.
18 | // The matcher is run in the context of the document of the current
19 | // Selection object.
20 | func (s *Selection) AddMatcher(m Matcher) *Selection {
21 | return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...)
22 | }
23 |
24 | // AddSelection adds the specified Selection object's nodes to those in the
25 | // current selection and returns a new Selection object.
26 | func (s *Selection) AddSelection(sel *Selection) *Selection {
27 | if sel == nil {
28 | return s.AddNodes()
29 | }
30 | return s.AddNodes(sel.Nodes...)
31 | }
32 |
33 | // Union is an alias for AddSelection.
34 | func (s *Selection) Union(sel *Selection) *Selection {
35 | return s.AddSelection(sel)
36 | }
37 |
38 | // AddNodes adds the specified nodes to those in the
39 | // current selection and returns a new Selection object.
40 | func (s *Selection) AddNodes(nodes ...*html.Node) *Selection {
41 | return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes))
42 | }
43 |
44 | // AndSelf adds the previous set of elements on the stack to the current set.
45 | // It returns a new Selection object containing the current Selection combined
46 | // with the previous one.
47 | func (s *Selection) AndSelf() *Selection {
48 | return s.AddSelection(s.prevSel)
49 | }
50 |
--------------------------------------------------------------------------------
/vendor/github.com/PuerkitoBio/goquery/iteration.go:
--------------------------------------------------------------------------------
1 | package goquery
2 |
3 | // Each iterates over a Selection object, executing a function for each
4 | // matched element. It returns the current Selection object.
5 | func (s *Selection) Each(f func(int, *Selection)) *Selection {
6 | for i, n := range s.Nodes {
7 | f(i, newSingleSelection(n, s.document))
8 | }
9 | return s
10 | }
11 |
12 | // EachWithBreak iterates over a Selection object, executing a function for each
13 | // matched element. It is identical to Each except that it is possible to break
14 | // out of the loop by returning false in the callback function. It returns the
15 | // current Selection object.
16 | func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection {
17 | for i, n := range s.Nodes {
18 | if !f(i, newSingleSelection(n, s.document)) {
19 | return s
20 | }
21 | }
22 | return s
23 | }
24 |
25 | // Map passes each element in the current matched set through a function,
26 | // producing a slice of string holding the returned values.
27 | func (s *Selection) Map(f func(int, *Selection) string) (result []string) {
28 | for i, n := range s.Nodes {
29 | result = append(result, f(i, newSingleSelection(n, s.document)))
30 | }
31 |
32 | return result
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/github.com/PuerkitoBio/goquery/query.go:
--------------------------------------------------------------------------------
1 | package goquery
2 |
3 | import (
4 | "github.com/andybalholm/cascadia"
5 | "golang.org/x/net/html"
6 | )
7 |
8 | // Is checks the current matched set of elements against a selector and
9 | // returns true if at least one of these elements matches.
10 | func (s *Selection) Is(selector string) bool {
11 | if len(s.Nodes) > 0 {
12 | return s.IsMatcher(cascadia.MustCompile(selector))
13 | }
14 |
15 | return false
16 | }
17 |
18 | // IsMatcher checks the current matched set of elements against a matcher and
19 | // returns true if at least one of these elements matches.
20 | func (s *Selection) IsMatcher(m Matcher) bool {
21 | if len(s.Nodes) > 0 {
22 | if len(s.Nodes) == 1 {
23 | return m.Match(s.Nodes[0])
24 | }
25 | return len(m.Filter(s.Nodes)) > 0
26 | }
27 |
28 | return false
29 | }
30 |
31 | // IsFunction checks the current matched set of elements against a predicate and
32 | // returns true if at least one of these elements matches.
33 | func (s *Selection) IsFunction(f func(int, *Selection) bool) bool {
34 | return s.FilterFunction(f).Length() > 0
35 | }
36 |
37 | // IsSelection checks the current matched set of elements against a Selection object
38 | // and returns true if at least one of these elements matches.
39 | func (s *Selection) IsSelection(sel *Selection) bool {
40 | return s.FilterSelection(sel).Length() > 0
41 | }
42 |
43 | // IsNodes checks the current matched set of elements against the specified nodes
44 | // and returns true if at least one of these elements matches.
45 | func (s *Selection) IsNodes(nodes ...*html.Node) bool {
46 | return s.FilterNodes(nodes...).Length() > 0
47 | }
48 |
49 | // Contains returns true if the specified Node is within,
50 | // at any depth, one of the nodes in the Selection object.
51 | // It is NOT inclusive, to behave like jQuery's implementation, and
52 | // unlike Javascript's .contains, so if the contained
53 | // node is itself in the selection, it returns false.
54 | func (s *Selection) Contains(n *html.Node) bool {
55 | return sliceContains(s.Nodes, n)
56 | }
57 |
--------------------------------------------------------------------------------
/vendor/github.com/andybalholm/cascadia/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 Andy Balholm. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/vendor/github.com/andybalholm/cascadia/README.md:
--------------------------------------------------------------------------------
1 | # cascadia
2 |
3 | [](https://travis-ci.org/andybalholm/cascadia)
4 |
5 | The Cascadia package implements CSS selectors for use with the parse trees produced by the html package.
6 |
--------------------------------------------------------------------------------
/vendor/github.com/br0xen/termbox-util/README.md:
--------------------------------------------------------------------------------
1 | termbox-util
2 | ============
3 |
4 | Utility Library for Termbox
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2005-2008 Dustin Sallings
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
21 |
22 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/README.markdown:
--------------------------------------------------------------------------------
1 | # Humane Units
2 |
3 | Just a few functions for helping humanize times and sizes.
4 |
5 | `go get` it as `github.com/dustin/go-humanize`, import it as
6 | `"github.com/dustin/go-humanize"`, use it as `humanize`
7 |
8 | See [godoc](https://godoc.org/github.com/dustin/go-humanize) for
9 | complete documentation.
10 |
11 | ## Sizes
12 |
13 | This lets you take numbers like `82854982` and convert them to useful
14 | strings like, `83MB` or `79MiB` (whichever you prefer).
15 |
16 | Example:
17 |
18 | ```go
19 | fmt.Printf("That file is %s.", humanize.Bytes(82854982))
20 | ```
21 |
22 | ## Times
23 |
24 | This lets you take a `time.Time` and spit it out in relative terms.
25 | For example, `12 seconds ago` or `3 days from now`.
26 |
27 | Example:
28 |
29 | ```go
30 | fmt.Printf("This was touched %s", humanize.Time(someTimeInstance))
31 | ```
32 |
33 | Thanks to Kyle Lemons for the time implementation from an IRC
34 | conversation one day. It's pretty neat.
35 |
36 | ## Ordinals
37 |
38 | From a [mailing list discussion][odisc] where a user wanted to be able
39 | to label ordinals.
40 |
41 | 0 -> 0th
42 | 1 -> 1st
43 | 2 -> 2nd
44 | 3 -> 3rd
45 | 4 -> 4th
46 | [...]
47 |
48 | Example:
49 |
50 | ```go
51 | fmt.Printf("You're my %s best friend.", humanize.Ordinal(193))
52 | ```
53 |
54 | ## Commas
55 |
56 | Want to shove commas into numbers? Be my guest.
57 |
58 | 0 -> 0
59 | 100 -> 100
60 | 1000 -> 1,000
61 | 1000000000 -> 1,000,000,000
62 | -100000 -> -100,000
63 |
64 | Example:
65 |
66 | ```go
67 | fmt.Printf("You owe $%s.\n", humanize.Comma(6582491))
68 | ```
69 |
70 | ## Ftoa
71 |
72 | Nicer float64 formatter that removes trailing zeros.
73 |
74 | ```go
75 | fmt.Printf("%f", 2.24) // 2.240000
76 | fmt.Printf("%s", humanize.Ftoa(2.24)) // 2.24
77 | fmt.Printf("%f", 2.0) // 2.000000
78 | fmt.Printf("%s", humanize.Ftoa(2.0)) // 2
79 | ```
80 |
81 | ## SI notation
82 |
83 | Format numbers with [SI notation][sinotation].
84 |
85 | Example:
86 |
87 | ```go
88 | humanize.SI(0.00000000223, "M") // 2.23nM
89 | ```
90 |
91 | [odisc]: https://groups.google.com/d/topic/golang-nuts/l8NhI74jl-4/discussion
92 | [sinotation]: http://en.wikipedia.org/wiki/Metric_prefix
93 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/big.go:
--------------------------------------------------------------------------------
1 | package humanize
2 |
3 | import (
4 | "math/big"
5 | )
6 |
7 | // order of magnitude (to a max order)
8 | func oomm(n, b *big.Int, maxmag int) (float64, int) {
9 | mag := 0
10 | m := &big.Int{}
11 | for n.Cmp(b) >= 0 {
12 | n.DivMod(n, b, m)
13 | mag++
14 | if mag == maxmag && maxmag >= 0 {
15 | break
16 | }
17 | }
18 | return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag
19 | }
20 |
21 | // total order of magnitude
22 | // (same as above, but with no upper limit)
23 | func oom(n, b *big.Int) (float64, int) {
24 | mag := 0
25 | m := &big.Int{}
26 | for n.Cmp(b) >= 0 {
27 | n.DivMod(n, b, m)
28 | mag++
29 | }
30 | return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag
31 | }
32 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/bytes.go:
--------------------------------------------------------------------------------
1 | package humanize
2 |
3 | import (
4 | "fmt"
5 | "math"
6 | "strconv"
7 | "strings"
8 | "unicode"
9 | )
10 |
11 | // IEC Sizes.
12 | // kibis of bits
13 | const (
14 | Byte = 1 << (iota * 10)
15 | KiByte
16 | MiByte
17 | GiByte
18 | TiByte
19 | PiByte
20 | EiByte
21 | )
22 |
23 | // SI Sizes.
24 | const (
25 | IByte = 1
26 | KByte = IByte * 1000
27 | MByte = KByte * 1000
28 | GByte = MByte * 1000
29 | TByte = GByte * 1000
30 | PByte = TByte * 1000
31 | EByte = PByte * 1000
32 | )
33 |
34 | var bytesSizeTable = map[string]uint64{
35 | "b": Byte,
36 | "kib": KiByte,
37 | "kb": KByte,
38 | "mib": MiByte,
39 | "mb": MByte,
40 | "gib": GiByte,
41 | "gb": GByte,
42 | "tib": TiByte,
43 | "tb": TByte,
44 | "pib": PiByte,
45 | "pb": PByte,
46 | "eib": EiByte,
47 | "eb": EByte,
48 | // Without suffix
49 | "": Byte,
50 | "ki": KiByte,
51 | "k": KByte,
52 | "mi": MiByte,
53 | "m": MByte,
54 | "gi": GiByte,
55 | "g": GByte,
56 | "ti": TiByte,
57 | "t": TByte,
58 | "pi": PiByte,
59 | "p": PByte,
60 | "ei": EiByte,
61 | "e": EByte,
62 | }
63 |
64 | func logn(n, b float64) float64 {
65 | return math.Log(n) / math.Log(b)
66 | }
67 |
68 | func humanateBytes(s uint64, base float64, sizes []string) string {
69 | if s < 10 {
70 | return fmt.Sprintf("%d B", s)
71 | }
72 | e := math.Floor(logn(float64(s), base))
73 | suffix := sizes[int(e)]
74 | val := math.Floor(float64(s)/math.Pow(base, e)*10+0.5) / 10
75 | f := "%.0f %s"
76 | if val < 10 {
77 | f = "%.1f %s"
78 | }
79 |
80 | return fmt.Sprintf(f, val, suffix)
81 | }
82 |
83 | // Bytes produces a human readable representation of an SI size.
84 | //
85 | // See also: ParseBytes.
86 | //
87 | // Bytes(82854982) -> 83MB
88 | func Bytes(s uint64) string {
89 | sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"}
90 | return humanateBytes(s, 1000, sizes)
91 | }
92 |
93 | // IBytes produces a human readable representation of an IEC size.
94 | //
95 | // See also: ParseBytes.
96 | //
97 | // IBytes(82854982) -> 79MiB
98 | func IBytes(s uint64) string {
99 | sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}
100 | return humanateBytes(s, 1024, sizes)
101 | }
102 |
103 | // ParseBytes parses a string representation of bytes into the number
104 | // of bytes it represents.
105 | //
106 | // See Also: Bytes, IBytes.
107 | //
108 | // ParseBytes("42MB") -> 42000000, nil
109 | // ParseBytes("42mib") -> 44040192, nil
110 | func ParseBytes(s string) (uint64, error) {
111 | lastDigit := 0
112 | for _, r := range s {
113 | if !(unicode.IsDigit(r) || r == '.') {
114 | break
115 | }
116 | lastDigit++
117 | }
118 |
119 | f, err := strconv.ParseFloat(s[:lastDigit], 64)
120 | if err != nil {
121 | return 0, err
122 | }
123 |
124 | extra := strings.ToLower(strings.TrimSpace(s[lastDigit:]))
125 | if m, ok := bytesSizeTable[extra]; ok {
126 | f *= float64(m)
127 | if f >= math.MaxUint64 {
128 | return 0, fmt.Errorf("too large: %v", s)
129 | }
130 | return uint64(f), nil
131 | }
132 |
133 | return 0, fmt.Errorf("unhandled size name: %v", extra)
134 | }
135 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/comma.go:
--------------------------------------------------------------------------------
1 | package humanize
2 |
3 | import (
4 | "bytes"
5 | "math/big"
6 | "strconv"
7 | "strings"
8 | )
9 |
10 | // Comma produces a string form of the given number in base 10 with
11 | // commas after every three orders of magnitude.
12 | //
13 | // e.g. Comma(834142) -> 834,142
14 | func Comma(v int64) string {
15 | sign := ""
16 | if v < 0 {
17 | sign = "-"
18 | v = 0 - v
19 | }
20 |
21 | parts := []string{"", "", "", "", "", "", ""}
22 | j := len(parts) - 1
23 |
24 | for v > 999 {
25 | parts[j] = strconv.FormatInt(v%1000, 10)
26 | switch len(parts[j]) {
27 | case 2:
28 | parts[j] = "0" + parts[j]
29 | case 1:
30 | parts[j] = "00" + parts[j]
31 | }
32 | v = v / 1000
33 | j--
34 | }
35 | parts[j] = strconv.Itoa(int(v))
36 | return sign + strings.Join(parts[j:], ",")
37 | }
38 |
39 | // Commaf produces a string form of the given number in base 10 with
40 | // commas after every three orders of magnitude.
41 | //
42 | // e.g. Comma(834142.32) -> 834,142.32
43 | func Commaf(v float64) string {
44 | buf := &bytes.Buffer{}
45 | if v < 0 {
46 | buf.Write([]byte{'-'})
47 | v = 0 - v
48 | }
49 |
50 | comma := []byte{','}
51 |
52 | parts := strings.Split(strconv.FormatFloat(v, 'f', -1, 64), ".")
53 | pos := 0
54 | if len(parts[0])%3 != 0 {
55 | pos += len(parts[0]) % 3
56 | buf.WriteString(parts[0][:pos])
57 | buf.Write(comma)
58 | }
59 | for ; pos < len(parts[0]); pos += 3 {
60 | buf.WriteString(parts[0][pos : pos+3])
61 | buf.Write(comma)
62 | }
63 | buf.Truncate(buf.Len() - 1)
64 |
65 | if len(parts) > 1 {
66 | buf.Write([]byte{'.'})
67 | buf.WriteString(parts[1])
68 | }
69 | return buf.String()
70 | }
71 |
72 | // BigComma produces a string form of the given big.Int in base 10
73 | // with commas after every three orders of magnitude.
74 | func BigComma(b *big.Int) string {
75 | sign := ""
76 | if b.Sign() < 0 {
77 | sign = "-"
78 | b.Abs(b)
79 | }
80 |
81 | athousand := big.NewInt(1000)
82 | c := (&big.Int{}).Set(b)
83 | _, m := oom(c, athousand)
84 | parts := make([]string, m+1)
85 | j := len(parts) - 1
86 |
87 | mod := &big.Int{}
88 | for b.Cmp(athousand) >= 0 {
89 | b.DivMod(b, athousand, mod)
90 | parts[j] = strconv.FormatInt(mod.Int64(), 10)
91 | switch len(parts[j]) {
92 | case 2:
93 | parts[j] = "0" + parts[j]
94 | case 1:
95 | parts[j] = "00" + parts[j]
96 | }
97 | j--
98 | }
99 | parts[j] = strconv.Itoa(int(b.Int64()))
100 | return sign + strings.Join(parts[j:], ",")
101 | }
102 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/ftoa.go:
--------------------------------------------------------------------------------
1 | package humanize
2 |
3 | import "strconv"
4 |
5 | func stripTrailingZeros(s string) string {
6 | offset := len(s) - 1
7 | for offset > 0 {
8 | if s[offset] == '.' {
9 | offset--
10 | break
11 | }
12 | if s[offset] != '0' {
13 | break
14 | }
15 | offset--
16 | }
17 | return s[:offset+1]
18 | }
19 |
20 | // Ftoa converts a float to a string with no trailing zeros.
21 | func Ftoa(num float64) string {
22 | return stripTrailingZeros(strconv.FormatFloat(num, 'f', 6, 64))
23 | }
24 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/humanize.go:
--------------------------------------------------------------------------------
1 | /*
2 | Package humanize converts boring ugly numbers to human-friendly strings and back.
3 |
4 | Durations can be turned into strings such as "3 days ago", numbers
5 | representing sizes like 82854982 into useful strings like, "83MB" or
6 | "79MiB" (whichever you prefer).
7 | */
8 | package humanize
9 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/ordinals.go:
--------------------------------------------------------------------------------
1 | package humanize
2 |
3 | import "strconv"
4 |
5 | // Ordinal gives you the input number in a rank/ordinal format.
6 | //
7 | // Ordinal(3) -> 3rd
8 | func Ordinal(x int) string {
9 | suffix := "th"
10 | switch x % 10 {
11 | case 1:
12 | if x%100 != 11 {
13 | suffix = "st"
14 | }
15 | case 2:
16 | if x%100 != 12 {
17 | suffix = "nd"
18 | }
19 | case 3:
20 | if x%100 != 13 {
21 | suffix = "rd"
22 | }
23 | }
24 | return strconv.Itoa(x) + suffix
25 | }
26 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/si.go:
--------------------------------------------------------------------------------
1 | package humanize
2 |
3 | import (
4 | "errors"
5 | "math"
6 | "regexp"
7 | "strconv"
8 | )
9 |
10 | var siPrefixTable = map[float64]string{
11 | -24: "y", // yocto
12 | -21: "z", // zepto
13 | -18: "a", // atto
14 | -15: "f", // femto
15 | -12: "p", // pico
16 | -9: "n", // nano
17 | -6: "µ", // micro
18 | -3: "m", // milli
19 | 0: "",
20 | 3: "k", // kilo
21 | 6: "M", // mega
22 | 9: "G", // giga
23 | 12: "T", // tera
24 | 15: "P", // peta
25 | 18: "E", // exa
26 | 21: "Z", // zetta
27 | 24: "Y", // yotta
28 | }
29 |
30 | var revSIPrefixTable = revfmap(siPrefixTable)
31 |
32 | // revfmap reverses the map and precomputes the power multiplier
33 | func revfmap(in map[float64]string) map[string]float64 {
34 | rv := map[string]float64{}
35 | for k, v := range in {
36 | rv[v] = math.Pow(10, k)
37 | }
38 | return rv
39 | }
40 |
41 | var riParseRegex *regexp.Regexp
42 |
43 | func init() {
44 | ri := `^([0-9.]+)\s?([`
45 | for _, v := range siPrefixTable {
46 | ri += v
47 | }
48 | ri += `]?)(.*)`
49 |
50 | riParseRegex = regexp.MustCompile(ri)
51 | }
52 |
53 | // ComputeSI finds the most appropriate SI prefix for the given number
54 | // and returns the prefix along with the value adjusted to be within
55 | // that prefix.
56 | //
57 | // See also: SI, ParseSI.
58 | //
59 | // e.g. ComputeSI(2.2345e-12) -> (2.2345, "p")
60 | func ComputeSI(input float64) (float64, string) {
61 | if input == 0 {
62 | return 0, ""
63 | }
64 | exponent := math.Floor(logn(input, 10))
65 | exponent = math.Floor(exponent/3) * 3
66 |
67 | value := input / math.Pow(10, exponent)
68 |
69 | // Handle special case where value is exactly 1000.0
70 | // Should return 1M instead of 1000k
71 | if value == 1000.0 {
72 | exponent += 3
73 | value = input / math.Pow(10, exponent)
74 | }
75 |
76 | prefix := siPrefixTable[exponent]
77 | return value, prefix
78 | }
79 |
80 | // SI returns a string with default formatting.
81 | //
82 | // SI uses Ftoa to format float value, removing trailing zeros.
83 | //
84 | // See also: ComputeSI, ParseSI.
85 | //
86 | // e.g. SI(1000000, B) -> 1MB
87 | // e.g. SI(2.2345e-12, "F") -> 2.2345pF
88 | func SI(input float64, unit string) string {
89 | value, prefix := ComputeSI(input)
90 | return Ftoa(value) + " " + prefix + unit
91 | }
92 |
93 | var errInvalid = errors.New("invalid input")
94 |
95 | // ParseSI parses an SI string back into the number and unit.
96 | //
97 | // See also: SI, ComputeSI.
98 | //
99 | // e.g. ParseSI(2.2345pF) -> (2.2345e-12, "F", nil)
100 | func ParseSI(input string) (float64, string, error) {
101 | found := riParseRegex.FindStringSubmatch(input)
102 | if len(found) != 4 {
103 | return 0, "", errInvalid
104 | }
105 | mag := revSIPrefixTable[found[2]]
106 | unit := found[3]
107 |
108 | base, err := strconv.ParseFloat(found[1], 64)
109 | return base * mag, unit, err
110 | }
111 |
--------------------------------------------------------------------------------
/vendor/github.com/dustin/go-humanize/times.go:
--------------------------------------------------------------------------------
1 | package humanize
2 |
3 | import (
4 | "fmt"
5 | "math"
6 | "sort"
7 | "time"
8 | )
9 |
10 | // Seconds-based time units
11 | const (
12 | Minute = 60
13 | Hour = 60 * Minute
14 | Day = 24 * Hour
15 | Week = 7 * Day
16 | Month = 30 * Day
17 | Year = 12 * Month
18 | LongTime = 37 * Year
19 | )
20 |
21 | // Time formats a time into a relative string.
22 | //
23 | // Time(someT) -> "3 weeks ago"
24 | func Time(then time.Time) string {
25 | return RelTime(then, time.Now(), "ago", "from now")
26 | }
27 |
28 | var magnitudes = []struct {
29 | d int64
30 | format string
31 | divby int64
32 | }{
33 | {1, "now", 1},
34 | {2, "1 second %s", 1},
35 | {Minute, "%d seconds %s", 1},
36 | {2 * Minute, "1 minute %s", 1},
37 | {Hour, "%d minutes %s", Minute},
38 | {2 * Hour, "1 hour %s", 1},
39 | {Day, "%d hours %s", Hour},
40 | {2 * Day, "1 day %s", 1},
41 | {Week, "%d days %s", Day},
42 | {2 * Week, "1 week %s", 1},
43 | {Month, "%d weeks %s", Week},
44 | {2 * Month, "1 month %s", 1},
45 | {Year, "%d months %s", Month},
46 | {18 * Month, "1 year %s", 1},
47 | {2 * Year, "2 years %s", 1},
48 | {LongTime, "%d years %s", Year},
49 | {math.MaxInt64, "a long while %s", 1},
50 | }
51 |
52 | // RelTime formats a time into a relative string.
53 | //
54 | // It takes two times and two labels. In addition to the generic time
55 | // delta string (e.g. 5 minutes), the labels are used applied so that
56 | // the label corresponding to the smaller time is applied.
57 | //
58 | // RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier"
59 | func RelTime(a, b time.Time, albl, blbl string) string {
60 | lbl := albl
61 | diff := b.Unix() - a.Unix()
62 |
63 | after := a.After(b)
64 | if after {
65 | lbl = blbl
66 | diff = a.Unix() - b.Unix()
67 | }
68 |
69 | n := sort.Search(len(magnitudes), func(i int) bool {
70 | return magnitudes[i].d > diff
71 | })
72 |
73 | mag := magnitudes[n]
74 | args := []interface{}{}
75 | escaped := false
76 | for _, ch := range mag.format {
77 | if escaped {
78 | switch ch {
79 | case '%':
80 | case 's':
81 | args = append(args, lbl)
82 | case 'd':
83 | args = append(args, diff/mag.divby)
84 | }
85 | escaped = false
86 | } else {
87 | escaped = ch == '%'
88 | }
89 | }
90 | return fmt.Sprintf(mag.format, args...)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/context/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/context/README.md:
--------------------------------------------------------------------------------
1 | context
2 | =======
3 | [](https://travis-ci.org/gorilla/context)
4 |
5 | gorilla/context is a general purpose registry for global request variables.
6 |
7 | Read the full documentation here: http://www.gorillatoolkit.org/pkg/context
8 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/context/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Gorilla Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | Package context stores values shared during a request lifetime.
7 |
8 | For example, a router can set variables extracted from the URL and later
9 | application handlers can access those values, or it can be used to store
10 | sessions values to be saved at the end of a request. There are several
11 | others common uses.
12 |
13 | The idea was posted by Brad Fitzpatrick to the go-nuts mailing list:
14 |
15 | http://groups.google.com/group/golang-nuts/msg/e2d679d303aa5d53
16 |
17 | Here's the basic usage: first define the keys that you will need. The key
18 | type is interface{} so a key can be of any type that supports equality.
19 | Here we define a key using a custom int type to avoid name collisions:
20 |
21 | package foo
22 |
23 | import (
24 | "github.com/gorilla/context"
25 | )
26 |
27 | type key int
28 |
29 | const MyKey key = 0
30 |
31 | Then set a variable. Variables are bound to an http.Request object, so you
32 | need a request instance to set a value:
33 |
34 | context.Set(r, MyKey, "bar")
35 |
36 | The application can later access the variable using the same key you provided:
37 |
38 | func MyHandler(w http.ResponseWriter, r *http.Request) {
39 | // val is "bar".
40 | val := context.Get(r, foo.MyKey)
41 |
42 | // returns ("bar", true)
43 | val, ok := context.GetOk(r, foo.MyKey)
44 | // ...
45 | }
46 |
47 | And that's all about the basic usage. We discuss some other ideas below.
48 |
49 | Any type can be stored in the context. To enforce a given type, make the key
50 | private and wrap Get() and Set() to accept and return values of a specific
51 | type:
52 |
53 | type key int
54 |
55 | const mykey key = 0
56 |
57 | // GetMyKey returns a value for this package from the request values.
58 | func GetMyKey(r *http.Request) SomeType {
59 | if rv := context.Get(r, mykey); rv != nil {
60 | return rv.(SomeType)
61 | }
62 | return nil
63 | }
64 |
65 | // SetMyKey sets a value for this package in the request values.
66 | func SetMyKey(r *http.Request, val SomeType) {
67 | context.Set(r, mykey, val)
68 | }
69 |
70 | Variables must be cleared at the end of a request, to remove all values
71 | that were stored. This can be done in an http.Handler, after a request was
72 | served. Just call Clear() passing the request:
73 |
74 | context.Clear(r)
75 |
76 | ...or use ClearHandler(), which conveniently wraps an http.Handler to clear
77 | variables at the end of a request lifetime.
78 |
79 | The Routers from the packages gorilla/mux and gorilla/pat call Clear()
80 | so if you are using either of them you don't need to clear the context manually.
81 | */
82 | package context
83 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/mux/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/justinas/alice/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Justinas Stankevicius
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/vendor/github.com/justinas/alice/README.md:
--------------------------------------------------------------------------------
1 | # Alice
2 |
3 | [](http://godoc.org/github.com/justinas/alice)
4 | [](https://travis-ci.org/justinas/alice)
5 | [](http://gocover.io/github.com/justinas/alice)
6 |
7 | Alice provides a convenient way to chain
8 | your HTTP middleware functions and the app handler.
9 |
10 | In short, it transforms
11 |
12 | Middleware1(Middleware2(Middleware3(App)))
13 |
14 | to
15 |
16 | alice.New(Middleware1, Middleware2, Middleware3).Then(App).
17 |
18 | ### Why?
19 |
20 | None of the other middleware chaining solutions
21 | behaves exactly like Alice.
22 | Alice is as minimal as it gets:
23 | in essence, it's just a for loop that does the wrapping for you.
24 |
25 | Check out [this blog post](http://justinas.org/alice-painless-middleware-chaining-for-go/)
26 | for explanation how Alice is different from other chaining solutions.
27 |
28 | ### Usage
29 |
30 | Your middleware constructors should have the form of
31 |
32 | func (http.Handler) http.Handler
33 |
34 | Some middleware provide this out of the box.
35 | For ones that don't, it's trivial to write one yourself.
36 |
37 | ```go
38 | func myStripPrefix(h http.Handler) http.Handler {
39 | return http.StripPrefix("/old", h)
40 | }
41 | ```
42 |
43 | This complete example shows the full power of Alice.
44 |
45 | ```go
46 | package main
47 |
48 | import (
49 | "net/http"
50 | "time"
51 |
52 | "github.com/PuerkitoBio/throttled"
53 | "github.com/justinas/alice"
54 | "github.com/justinas/nosurf"
55 | )
56 |
57 | func timeoutHandler(h http.Handler) http.Handler {
58 | return http.TimeoutHandler(h, 1*time.Second, "timed out")
59 | }
60 |
61 | func myApp(w http.ResponseWriter, r *http.Request) {
62 | w.Write([]byte("Hello world!"))
63 | }
64 |
65 | func main() {
66 | th := throttled.Interval(throttled.PerSec(10), 1, &throttled.VaryBy{Path: true}, 50)
67 | myHandler := http.HandlerFunc(myApp)
68 |
69 | chain := alice.New(th.Throttle, timeoutHandler, nosurf.NewPure).Then(myHandler)
70 | http.ListenAndServe(":8000", chain)
71 | }
72 | ```
73 |
74 | Here, the request will pass [throttled](https://github.com/PuerkitoBio/throttled) first,
75 | then an http.TimeoutHandler we've set up,
76 | then [nosurf](https://github.com/justinas/nosurf)
77 | and will finally reach our handler.
78 |
79 | Note that Alice makes **no guarantees** for
80 | how one or another piece of middleware will behave.
81 | It executes all middleware sequentially so that if a
82 | piece of middleware were to stop the chain,
83 | the request will not reach the inner handlers.
84 | This is intentional behavior.
85 |
86 | Alice works with Go 1.0 and higher,
87 | but running tests requires at least Go 1.1.
88 |
89 | ### Contributing
90 |
91 | 0. Find an issue that bugs you / open a new one.
92 | 1. Discuss.
93 | 2. Branch off, commit, test.
94 | 3. Make a pull request / attach the commits to the issue.
95 |
--------------------------------------------------------------------------------
/vendor/github.com/kr/fs/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/kr/fs/Readme:
--------------------------------------------------------------------------------
1 | Filesystem Package
2 |
3 | http://godoc.org/github.com/kr/fs
4 |
--------------------------------------------------------------------------------
/vendor/github.com/kr/fs/filesystem.go:
--------------------------------------------------------------------------------
1 | package fs
2 |
3 | import (
4 | "io/ioutil"
5 | "os"
6 | "path/filepath"
7 | )
8 |
9 | // FileSystem defines the methods of an abstract filesystem.
10 | type FileSystem interface {
11 |
12 | // ReadDir reads the directory named by dirname and returns a
13 | // list of directory entries.
14 | ReadDir(dirname string) ([]os.FileInfo, error)
15 |
16 | // Lstat returns a FileInfo describing the named file. If the file is a
17 | // symbolic link, the returned FileInfo describes the symbolic link. Lstat
18 | // makes no attempt to follow the link.
19 | Lstat(name string) (os.FileInfo, error)
20 |
21 | // Join joins any number of path elements into a single path, adding a
22 | // separator if necessary. The result is Cleaned; in particular, all
23 | // empty strings are ignored.
24 | //
25 | // The separator is FileSystem specific.
26 | Join(elem ...string) string
27 | }
28 |
29 | // fs represents a FileSystem provided by the os package.
30 | type fs struct{}
31 |
32 | func (f *fs) ReadDir(dirname string) ([]os.FileInfo, error) { return ioutil.ReadDir(dirname) }
33 |
34 | func (f *fs) Lstat(name string) (os.FileInfo, error) { return os.Lstat(name) }
35 |
36 | func (f *fs) Join(elem ...string) string { return filepath.Join(elem...) }
37 |
--------------------------------------------------------------------------------
/vendor/github.com/kr/fs/walk.go:
--------------------------------------------------------------------------------
1 | // Package fs provides filesystem-related functions.
2 | package fs
3 |
4 | import (
5 | "os"
6 | )
7 |
8 | // Walker provides a convenient interface for iterating over the
9 | // descendants of a filesystem path.
10 | // Successive calls to the Step method will step through each
11 | // file or directory in the tree, including the root. The files
12 | // are walked in lexical order, which makes the output deterministic
13 | // but means that for very large directories Walker can be inefficient.
14 | // Walker does not follow symbolic links.
15 | type Walker struct {
16 | fs FileSystem
17 | cur item
18 | stack []item
19 | descend bool
20 | }
21 |
22 | type item struct {
23 | path string
24 | info os.FileInfo
25 | err error
26 | }
27 |
28 | // Walk returns a new Walker rooted at root.
29 | func Walk(root string) *Walker {
30 | return WalkFS(root, new(fs))
31 | }
32 |
33 | // WalkFS returns a new Walker rooted at root on the FileSystem fs.
34 | func WalkFS(root string, fs FileSystem) *Walker {
35 | info, err := fs.Lstat(root)
36 | return &Walker{
37 | fs: fs,
38 | stack: []item{{root, info, err}},
39 | }
40 | }
41 |
42 | // Step advances the Walker to the next file or directory,
43 | // which will then be available through the Path, Stat,
44 | // and Err methods.
45 | // It returns false when the walk stops at the end of the tree.
46 | func (w *Walker) Step() bool {
47 | if w.descend && w.cur.err == nil && w.cur.info.IsDir() {
48 | list, err := w.fs.ReadDir(w.cur.path)
49 | if err != nil {
50 | w.cur.err = err
51 | w.stack = append(w.stack, w.cur)
52 | } else {
53 | for i := len(list) - 1; i >= 0; i-- {
54 | path := w.fs.Join(w.cur.path, list[i].Name())
55 | w.stack = append(w.stack, item{path, list[i], nil})
56 | }
57 | }
58 | }
59 |
60 | if len(w.stack) == 0 {
61 | return false
62 | }
63 | i := len(w.stack) - 1
64 | w.cur = w.stack[i]
65 | w.stack = w.stack[:i]
66 | w.descend = true
67 | return true
68 | }
69 |
70 | // Path returns the path to the most recent file or directory
71 | // visited by a call to Step. It contains the argument to Walk
72 | // as a prefix; that is, if Walk is called with "dir", which is
73 | // a directory containing the file "a", Path will return "dir/a".
74 | func (w *Walker) Path() string {
75 | return w.cur.path
76 | }
77 |
78 | // Stat returns info for the most recent file or directory
79 | // visited by a call to Step.
80 | func (w *Walker) Stat() os.FileInfo {
81 | return w.cur.info
82 | }
83 |
84 | // Err returns the error, if any, for the most recent attempt
85 | // by Step to visit a file or directory. If a directory has
86 | // an error, w will not descend into that directory.
87 | func (w *Walker) Err() error {
88 | return w.cur.err
89 | }
90 |
91 | // SkipDir causes the currently visited directory to be skipped.
92 | // If w is not on a directory, SkipDir has no effect.
93 | func (w *Walker) SkipDir() {
94 | w.descend = false
95 | }
96 |
--------------------------------------------------------------------------------
/vendor/github.com/mattn/go-runewidth/README.mkd:
--------------------------------------------------------------------------------
1 | go-runewidth
2 | ============
3 |
4 | [](https://travis-ci.org/mattn/go-runewidth)
5 | [](https://coveralls.io/r/mattn/go-runewidth?branch=HEAD)
6 | [](http://godoc.org/github.com/mattn/go-runewidth)
7 |
8 | Provides functions to get fixed width of the character or string.
9 |
10 | Usage
11 | -----
12 |
13 | ```go
14 | runewidth.StringWidth("つのだ☆HIRO") == 12
15 | ```
16 |
17 |
18 | Author
19 | ------
20 |
21 | Yasuhiro Matsumoto
22 |
23 | License
24 | -------
25 |
26 | under the MIT License: http://mattn.mit-license.org/2013
27 |
--------------------------------------------------------------------------------
/vendor/github.com/mattn/go-runewidth/runewidth_js.go:
--------------------------------------------------------------------------------
1 | // +build js
2 |
3 | package runewidth
4 |
5 | func IsEastAsian() bool {
6 | // TODO: Implement this for the web. Detect east asian in a compatible way, and return true.
7 | return false
8 | }
9 |
--------------------------------------------------------------------------------
/vendor/github.com/mattn/go-runewidth/runewidth_posix.go:
--------------------------------------------------------------------------------
1 | // +build !windows,!js
2 |
3 | package runewidth
4 |
5 | import (
6 | "os"
7 | "regexp"
8 | "strings"
9 | )
10 |
11 | var reLoc = regexp.MustCompile(`^[a-z][a-z][a-z]?(?:_[A-Z][A-Z])?\.(.+)`)
12 |
13 | func IsEastAsian() bool {
14 | locale := os.Getenv("LC_CTYPE")
15 | if locale == "" {
16 | locale = os.Getenv("LANG")
17 | }
18 |
19 | // ignore C locale
20 | if locale == "POSIX" || locale == "C" {
21 | return false
22 | }
23 | if len(locale) > 1 && locale[0] == 'C' && (locale[1] == '.' || locale[1] == '-') {
24 | return false
25 | }
26 |
27 | charset := strings.ToLower(locale)
28 | r := reLoc.FindStringSubmatch(locale)
29 | if len(r) == 2 {
30 | charset = strings.ToLower(r[1])
31 | }
32 |
33 | if strings.HasSuffix(charset, "@cjk_narrow") {
34 | return false
35 | }
36 |
37 | for pos, b := range []byte(charset) {
38 | if b == '@' {
39 | charset = charset[:pos]
40 | break
41 | }
42 | }
43 |
44 | mbc_max := 1
45 | switch charset {
46 | case "utf-8", "utf8":
47 | mbc_max = 6
48 | case "jis":
49 | mbc_max = 8
50 | case "eucjp":
51 | mbc_max = 3
52 | case "euckr", "euccn":
53 | mbc_max = 2
54 | case "sjis", "cp932", "cp51932", "cp936", "cp949", "cp950":
55 | mbc_max = 2
56 | case "big5":
57 | mbc_max = 2
58 | case "gbk", "gb2312":
59 | mbc_max = 2
60 | }
61 |
62 | if mbc_max > 1 && (charset[0] != 'u' ||
63 | strings.HasPrefix(locale, "ja") ||
64 | strings.HasPrefix(locale, "ko") ||
65 | strings.HasPrefix(locale, "zh")) {
66 | return true
67 | }
68 | return false
69 | }
70 |
--------------------------------------------------------------------------------
/vendor/github.com/mattn/go-runewidth/runewidth_windows.go:
--------------------------------------------------------------------------------
1 | package runewidth
2 |
3 | import (
4 | "syscall"
5 | )
6 |
7 | var (
8 | kernel32 = syscall.NewLazyDLL("kernel32")
9 | procGetConsoleOutputCP = kernel32.NewProc("GetConsoleOutputCP")
10 | )
11 |
12 | func IsEastAsian() bool {
13 | r1, _, _ := procGetConsoleOutputCP.Call()
14 | if r1 == 0 {
15 | return false
16 | }
17 |
18 | switch int(r1) {
19 | case 932, 51932, 936, 949, 950:
20 | return true
21 | }
22 |
23 | return false
24 | }
25 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/AUTHORS:
--------------------------------------------------------------------------------
1 | # Please keep this file sorted.
2 |
3 | Georg Reinke
4 | nsf
5 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2012 termbox-go authors
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/README.md:
--------------------------------------------------------------------------------
1 | ## Termbox
2 | Termbox is a library that provides a minimalistic API which allows the programmer to write text-based user interfaces. The library is crossplatform and has both terminal-based implementations on *nix operating systems and a winapi console based implementation for windows operating systems. The basic idea is an abstraction of the greatest common subset of features available on all major terminals and other terminal-like APIs in a minimalistic fashion. Small API means it is easy to implement, test, maintain and learn it, that's what makes the termbox a distinct library in its area.
3 |
4 | ### Installation
5 | Install and update this go package with `go get -u github.com/nsf/termbox-go`
6 |
7 | ### Examples
8 | For examples of what can be done take a look at demos in the _demos directory. You can try them with go run: `go run _demos/keyboard.go`
9 |
10 | There are also some interesting projects using termbox-go:
11 | - [godit](https://github.com/nsf/godit) is an emacsish lightweight text editor written using termbox.
12 | - [gomatrix](https://github.com/GeertJohan/gomatrix) connects to The Matrix and displays its data streams in your terminal.
13 | - [gotetris](https://github.com/jjinux/gotetris) is an implementation of Tetris.
14 | - [sokoban-go](https://github.com/rn2dy/sokoban-go) is an implementation of sokoban game.
15 | - [hecate](https://github.com/evanmiller/hecate) is a hex editor designed by Satan.
16 | - [httopd](https://github.com/verdverm/httopd) is top for httpd logs.
17 | - [mop](https://github.com/michaeldv/mop) is stock market tracker for hackers.
18 | - [termui](https://github.com/gizak/termui) is a terminal dashboard.
19 | - [termloop](https://github.com/JoelOtter/termloop) is a terminal game engine.
20 | - [xterm-color-chart](https://github.com/kutuluk/xterm-color-chart) is a XTerm 256 color chart.
21 | - [gocui](https://github.com/jroimartin/gocui) is a minimalist Go library aimed at creating console user interfaces.
22 | - [dry](https://github.com/moncho/dry) is an interactive cli to manage Docker containers.
23 |
24 | ### API reference
25 | [godoc.org/github.com/nsf/termbox-go](http://godoc.org/github.com/nsf/termbox-go)
26 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/collect_terminfo.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import sys, os, subprocess
4 |
5 | def escaped(s):
6 | return repr(s)[1:-1]
7 |
8 | def tput(term, name):
9 | try:
10 | return subprocess.check_output(['tput', '-T%s' % term, name]).decode()
11 | except subprocess.CalledProcessError as e:
12 | return e.output.decode()
13 |
14 |
15 | def w(s):
16 | if s == None:
17 | return
18 | sys.stdout.write(s)
19 |
20 | terminals = {
21 | 'xterm' : 'xterm',
22 | 'rxvt-256color' : 'rxvt_256color',
23 | 'rxvt-unicode' : 'rxvt_unicode',
24 | 'linux' : 'linux',
25 | 'Eterm' : 'eterm',
26 | 'screen' : 'screen'
27 | }
28 |
29 | keys = [
30 | "F1", "kf1",
31 | "F2", "kf2",
32 | "F3", "kf3",
33 | "F4", "kf4",
34 | "F5", "kf5",
35 | "F6", "kf6",
36 | "F7", "kf7",
37 | "F8", "kf8",
38 | "F9", "kf9",
39 | "F10", "kf10",
40 | "F11", "kf11",
41 | "F12", "kf12",
42 | "INSERT", "kich1",
43 | "DELETE", "kdch1",
44 | "HOME", "khome",
45 | "END", "kend",
46 | "PGUP", "kpp",
47 | "PGDN", "knp",
48 | "KEY_UP", "kcuu1",
49 | "KEY_DOWN", "kcud1",
50 | "KEY_LEFT", "kcub1",
51 | "KEY_RIGHT", "kcuf1"
52 | ]
53 |
54 | funcs = [
55 | "T_ENTER_CA", "smcup",
56 | "T_EXIT_CA", "rmcup",
57 | "T_SHOW_CURSOR", "cnorm",
58 | "T_HIDE_CURSOR", "civis",
59 | "T_CLEAR_SCREEN", "clear",
60 | "T_SGR0", "sgr0",
61 | "T_UNDERLINE", "smul",
62 | "T_BOLD", "bold",
63 | "T_BLINK", "blink",
64 | "T_REVERSE", "rev",
65 | "T_ENTER_KEYPAD", "smkx",
66 | "T_EXIT_KEYPAD", "rmkx"
67 | ]
68 |
69 | def iter_pairs(iterable):
70 | iterable = iter(iterable)
71 | while True:
72 | yield (next(iterable), next(iterable))
73 |
74 | def do_term(term, nick):
75 | w("// %s\n" % term)
76 | w("var %s_keys = []string{\n\t" % nick)
77 | for k, v in iter_pairs(keys):
78 | w('"')
79 | w(escaped(tput(term, v)))
80 | w('",')
81 | w("\n}\n")
82 | w("var %s_funcs = []string{\n\t" % nick)
83 | for k,v in iter_pairs(funcs):
84 | w('"')
85 | if v == "sgr":
86 | w("\\033[3%d;4%dm")
87 | elif v == "cup":
88 | w("\\033[%d;%dH")
89 | else:
90 | w(escaped(tput(term, v)))
91 | w('", ')
92 | w("\n}\n\n")
93 |
94 | def do_terms(d):
95 | w("var terms = []struct {\n")
96 | w("\tname string\n")
97 | w("\tkeys []string\n")
98 | w("\tfuncs []string\n")
99 | w("}{\n")
100 | for k, v in d.items():
101 | w('\t{"%s", %s_keys, %s_funcs},\n' % (k, v, v))
102 | w("}\n\n")
103 |
104 | w("// +build !windows\n\npackage termbox\n\n")
105 |
106 | for k,v in terminals.items():
107 | do_term(k, v)
108 |
109 | do_terms(terminals)
110 |
111 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package termbox
4 |
5 | /*
6 | #include
7 | #include
8 | */
9 | import "C"
10 |
11 | type syscall_Termios C.struct_termios
12 |
13 | const (
14 | syscall_IGNBRK = C.IGNBRK
15 | syscall_BRKINT = C.BRKINT
16 | syscall_PARMRK = C.PARMRK
17 | syscall_ISTRIP = C.ISTRIP
18 | syscall_INLCR = C.INLCR
19 | syscall_IGNCR = C.IGNCR
20 | syscall_ICRNL = C.ICRNL
21 | syscall_IXON = C.IXON
22 | syscall_OPOST = C.OPOST
23 | syscall_ECHO = C.ECHO
24 | syscall_ECHONL = C.ECHONL
25 | syscall_ICANON = C.ICANON
26 | syscall_ISIG = C.ISIG
27 | syscall_IEXTEN = C.IEXTEN
28 | syscall_CSIZE = C.CSIZE
29 | syscall_PARENB = C.PARENB
30 | syscall_CS8 = C.CS8
31 | syscall_VMIN = C.VMIN
32 | syscall_VTIME = C.VTIME
33 |
34 | // on darwin change these to (on *bsd too?):
35 | // C.TIOCGETA
36 | // C.TIOCSETA
37 | syscall_TCGETS = C.TCGETS
38 | syscall_TCSETS = C.TCSETS
39 | )
40 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls_darwin.go:
--------------------------------------------------------------------------------
1 | // Created by cgo -godefs - DO NOT EDIT
2 | // cgo -godefs syscalls.go
3 |
4 | // +build !amd64
5 |
6 | package termbox
7 |
8 | type syscall_Termios struct {
9 | Iflag uint32
10 | Oflag uint32
11 | Cflag uint32
12 | Lflag uint32
13 | Cc [20]uint8
14 | Ispeed uint32
15 | Ospeed uint32
16 | }
17 |
18 | const (
19 | syscall_IGNBRK = 0x1
20 | syscall_BRKINT = 0x2
21 | syscall_PARMRK = 0x8
22 | syscall_ISTRIP = 0x20
23 | syscall_INLCR = 0x40
24 | syscall_IGNCR = 0x80
25 | syscall_ICRNL = 0x100
26 | syscall_IXON = 0x200
27 | syscall_OPOST = 0x1
28 | syscall_ECHO = 0x8
29 | syscall_ECHONL = 0x10
30 | syscall_ICANON = 0x100
31 | syscall_ISIG = 0x80
32 | syscall_IEXTEN = 0x400
33 | syscall_CSIZE = 0x300
34 | syscall_PARENB = 0x1000
35 | syscall_CS8 = 0x300
36 | syscall_VMIN = 0x10
37 | syscall_VTIME = 0x11
38 |
39 | syscall_TCGETS = 0x402c7413
40 | syscall_TCSETS = 0x802c7414
41 | )
42 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls_darwin_amd64.go:
--------------------------------------------------------------------------------
1 | // Created by cgo -godefs - DO NOT EDIT
2 | // cgo -godefs syscalls.go
3 |
4 | package termbox
5 |
6 | type syscall_Termios struct {
7 | Iflag uint64
8 | Oflag uint64
9 | Cflag uint64
10 | Lflag uint64
11 | Cc [20]uint8
12 | Pad_cgo_0 [4]byte
13 | Ispeed uint64
14 | Ospeed uint64
15 | }
16 |
17 | const (
18 | syscall_IGNBRK = 0x1
19 | syscall_BRKINT = 0x2
20 | syscall_PARMRK = 0x8
21 | syscall_ISTRIP = 0x20
22 | syscall_INLCR = 0x40
23 | syscall_IGNCR = 0x80
24 | syscall_ICRNL = 0x100
25 | syscall_IXON = 0x200
26 | syscall_OPOST = 0x1
27 | syscall_ECHO = 0x8
28 | syscall_ECHONL = 0x10
29 | syscall_ICANON = 0x100
30 | syscall_ISIG = 0x80
31 | syscall_IEXTEN = 0x400
32 | syscall_CSIZE = 0x300
33 | syscall_PARENB = 0x1000
34 | syscall_CS8 = 0x300
35 | syscall_VMIN = 0x10
36 | syscall_VTIME = 0x11
37 |
38 | syscall_TCGETS = 0x40487413
39 | syscall_TCSETS = 0x80487414
40 | )
41 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls_freebsd.go:
--------------------------------------------------------------------------------
1 | // Created by cgo -godefs - DO NOT EDIT
2 | // cgo -godefs syscalls.go
3 |
4 | package termbox
5 |
6 | type syscall_Termios struct {
7 | Iflag uint32
8 | Oflag uint32
9 | Cflag uint32
10 | Lflag uint32
11 | Cc [20]uint8
12 | Ispeed uint32
13 | Ospeed uint32
14 | }
15 |
16 | const (
17 | syscall_IGNBRK = 0x1
18 | syscall_BRKINT = 0x2
19 | syscall_PARMRK = 0x8
20 | syscall_ISTRIP = 0x20
21 | syscall_INLCR = 0x40
22 | syscall_IGNCR = 0x80
23 | syscall_ICRNL = 0x100
24 | syscall_IXON = 0x200
25 | syscall_OPOST = 0x1
26 | syscall_ECHO = 0x8
27 | syscall_ECHONL = 0x10
28 | syscall_ICANON = 0x100
29 | syscall_ISIG = 0x80
30 | syscall_IEXTEN = 0x400
31 | syscall_CSIZE = 0x300
32 | syscall_PARENB = 0x1000
33 | syscall_CS8 = 0x300
34 | syscall_VMIN = 0x10
35 | syscall_VTIME = 0x11
36 |
37 | syscall_TCGETS = 0x402c7413
38 | syscall_TCSETS = 0x802c7414
39 | )
40 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls_linux.go:
--------------------------------------------------------------------------------
1 | // Created by cgo -godefs - DO NOT EDIT
2 | // cgo -godefs syscalls.go
3 |
4 | package termbox
5 |
6 | import "syscall"
7 |
8 | type syscall_Termios syscall.Termios
9 |
10 | const (
11 | syscall_IGNBRK = syscall.IGNBRK
12 | syscall_BRKINT = syscall.BRKINT
13 | syscall_PARMRK = syscall.PARMRK
14 | syscall_ISTRIP = syscall.ISTRIP
15 | syscall_INLCR = syscall.INLCR
16 | syscall_IGNCR = syscall.IGNCR
17 | syscall_ICRNL = syscall.ICRNL
18 | syscall_IXON = syscall.IXON
19 | syscall_OPOST = syscall.OPOST
20 | syscall_ECHO = syscall.ECHO
21 | syscall_ECHONL = syscall.ECHONL
22 | syscall_ICANON = syscall.ICANON
23 | syscall_ISIG = syscall.ISIG
24 | syscall_IEXTEN = syscall.IEXTEN
25 | syscall_CSIZE = syscall.CSIZE
26 | syscall_PARENB = syscall.PARENB
27 | syscall_CS8 = syscall.CS8
28 | syscall_VMIN = syscall.VMIN
29 | syscall_VTIME = syscall.VTIME
30 |
31 | syscall_TCGETS = syscall.TCGETS
32 | syscall_TCSETS = syscall.TCSETS
33 | )
34 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls_netbsd.go:
--------------------------------------------------------------------------------
1 | // Created by cgo -godefs - DO NOT EDIT
2 | // cgo -godefs syscalls.go
3 |
4 | package termbox
5 |
6 | type syscall_Termios struct {
7 | Iflag uint32
8 | Oflag uint32
9 | Cflag uint32
10 | Lflag uint32
11 | Cc [20]uint8
12 | Ispeed int32
13 | Ospeed int32
14 | }
15 |
16 | const (
17 | syscall_IGNBRK = 0x1
18 | syscall_BRKINT = 0x2
19 | syscall_PARMRK = 0x8
20 | syscall_ISTRIP = 0x20
21 | syscall_INLCR = 0x40
22 | syscall_IGNCR = 0x80
23 | syscall_ICRNL = 0x100
24 | syscall_IXON = 0x200
25 | syscall_OPOST = 0x1
26 | syscall_ECHO = 0x8
27 | syscall_ECHONL = 0x10
28 | syscall_ICANON = 0x100
29 | syscall_ISIG = 0x80
30 | syscall_IEXTEN = 0x400
31 | syscall_CSIZE = 0x300
32 | syscall_PARENB = 0x1000
33 | syscall_CS8 = 0x300
34 | syscall_VMIN = 0x10
35 | syscall_VTIME = 0x11
36 |
37 | syscall_TCGETS = 0x402c7413
38 | syscall_TCSETS = 0x802c7414
39 | )
40 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls_openbsd.go:
--------------------------------------------------------------------------------
1 | // Created by cgo -godefs - DO NOT EDIT
2 | // cgo -godefs syscalls.go
3 |
4 | package termbox
5 |
6 | type syscall_Termios struct {
7 | Iflag uint32
8 | Oflag uint32
9 | Cflag uint32
10 | Lflag uint32
11 | Cc [20]uint8
12 | Ispeed int32
13 | Ospeed int32
14 | }
15 |
16 | const (
17 | syscall_IGNBRK = 0x1
18 | syscall_BRKINT = 0x2
19 | syscall_PARMRK = 0x8
20 | syscall_ISTRIP = 0x20
21 | syscall_INLCR = 0x40
22 | syscall_IGNCR = 0x80
23 | syscall_ICRNL = 0x100
24 | syscall_IXON = 0x200
25 | syscall_OPOST = 0x1
26 | syscall_ECHO = 0x8
27 | syscall_ECHONL = 0x10
28 | syscall_ICANON = 0x100
29 | syscall_ISIG = 0x80
30 | syscall_IEXTEN = 0x400
31 | syscall_CSIZE = 0x300
32 | syscall_PARENB = 0x1000
33 | syscall_CS8 = 0x300
34 | syscall_VMIN = 0x10
35 | syscall_VTIME = 0x11
36 |
37 | syscall_TCGETS = 0x402c7413
38 | syscall_TCSETS = 0x802c7414
39 | )
40 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/syscalls_windows.go:
--------------------------------------------------------------------------------
1 | // Created by cgo -godefs - DO NOT EDIT
2 | // cgo -godefs -- -DUNICODE syscalls.go
3 |
4 | package termbox
5 |
6 | const (
7 | foreground_blue = 0x1
8 | foreground_green = 0x2
9 | foreground_red = 0x4
10 | foreground_intensity = 0x8
11 | background_blue = 0x10
12 | background_green = 0x20
13 | background_red = 0x40
14 | background_intensity = 0x80
15 | std_input_handle = -0xa
16 | std_output_handle = -0xb
17 | key_event = 0x1
18 | mouse_event = 0x2
19 | window_buffer_size_event = 0x4
20 | enable_window_input = 0x8
21 | enable_mouse_input = 0x10
22 | enable_extended_flags = 0x80
23 |
24 | vk_f1 = 0x70
25 | vk_f2 = 0x71
26 | vk_f3 = 0x72
27 | vk_f4 = 0x73
28 | vk_f5 = 0x74
29 | vk_f6 = 0x75
30 | vk_f7 = 0x76
31 | vk_f8 = 0x77
32 | vk_f9 = 0x78
33 | vk_f10 = 0x79
34 | vk_f11 = 0x7a
35 | vk_f12 = 0x7b
36 | vk_insert = 0x2d
37 | vk_delete = 0x2e
38 | vk_home = 0x24
39 | vk_end = 0x23
40 | vk_pgup = 0x21
41 | vk_pgdn = 0x22
42 | vk_arrow_up = 0x26
43 | vk_arrow_down = 0x28
44 | vk_arrow_left = 0x25
45 | vk_arrow_right = 0x27
46 | vk_backspace = 0x8
47 | vk_tab = 0x9
48 | vk_enter = 0xd
49 | vk_esc = 0x1b
50 | vk_space = 0x20
51 |
52 | left_alt_pressed = 0x2
53 | left_ctrl_pressed = 0x8
54 | right_alt_pressed = 0x1
55 | right_ctrl_pressed = 0x4
56 | shift_pressed = 0x10
57 |
58 | generic_read = 0x80000000
59 | generic_write = 0x40000000
60 | console_textmode_buffer = 0x1
61 | )
62 |
--------------------------------------------------------------------------------
/vendor/github.com/nsf/termbox-go/termbox_common.go:
--------------------------------------------------------------------------------
1 | package termbox
2 |
3 | // private API, common OS agnostic part
4 |
5 | type cellbuf struct {
6 | width int
7 | height int
8 | cells []Cell
9 | }
10 |
11 | func (this *cellbuf) init(width, height int) {
12 | this.width = width
13 | this.height = height
14 | this.cells = make([]Cell, width*height)
15 | }
16 |
17 | func (this *cellbuf) resize(width, height int) {
18 | if this.width == width && this.height == height {
19 | return
20 | }
21 |
22 | oldw := this.width
23 | oldh := this.height
24 | oldcells := this.cells
25 |
26 | this.init(width, height)
27 | this.clear()
28 |
29 | minw, minh := oldw, oldh
30 |
31 | if width < minw {
32 | minw = width
33 | }
34 | if height < minh {
35 | minh = height
36 | }
37 |
38 | for i := 0; i < minh; i++ {
39 | srco, dsto := i*oldw, i*width
40 | src := oldcells[srco : srco+minw]
41 | dst := this.cells[dsto : dsto+minw]
42 | copy(dst, src)
43 | }
44 | }
45 |
46 | func (this *cellbuf) clear() {
47 | for i := range this.cells {
48 | c := &this.cells[i]
49 | c.Ch = ' '
50 | c.Fg = foreground
51 | c.Bg = background
52 | }
53 | }
54 |
55 | const cursor_hidden = -1
56 |
57 | func is_cursor_hidden(x, y int) bool {
58 | return x == cursor_hidden || y == cursor_hidden
59 | }
60 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to contribute
2 |
3 | We definitely welcome patches and contribution to this project!
4 |
5 | ### Legal requirements
6 |
7 | In order to protect both you and ourselves, you will need to sign the
8 | [Contributor License Agreement](https://cla.developers.google.com/clas).
9 |
10 | You may have already signed it for other Google projects.
11 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | Paul Borman
2 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009,2014 Google Inc. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/README.md:
--------------------------------------------------------------------------------
1 | This project was automatically exported from code.google.com/p/go-uuid
2 |
3 | # uuid 
4 | The uuid package generates and inspects UUIDs based on [RFC 412](http://tools.ietf.org/html/rfc4122) and DCE 1.1: Authentication and Security Services.
5 |
6 | ###### Install
7 | `go get github.com/pborman/uuid`
8 |
9 | ###### Documentation
10 | [](http://godoc.org/github.com/pborman/uuid)
11 |
12 | Full `go doc` style documentation for the package can be viewed online without installing this package by using the GoDoc site here:
13 | http://godoc.org/github.com/pborman/uuid
14 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/dce.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | import (
8 | "encoding/binary"
9 | "fmt"
10 | "os"
11 | )
12 |
13 | // A Domain represents a Version 2 domain
14 | type Domain byte
15 |
16 | // Domain constants for DCE Security (Version 2) UUIDs.
17 | const (
18 | Person = Domain(0)
19 | Group = Domain(1)
20 | Org = Domain(2)
21 | )
22 |
23 | // NewDCESecurity returns a DCE Security (Version 2) UUID.
24 | //
25 | // The domain should be one of Person, Group or Org.
26 | // On a POSIX system the id should be the users UID for the Person
27 | // domain and the users GID for the Group. The meaning of id for
28 | // the domain Org or on non-POSIX systems is site defined.
29 | //
30 | // For a given domain/id pair the same token may be returned for up to
31 | // 7 minutes and 10 seconds.
32 | func NewDCESecurity(domain Domain, id uint32) UUID {
33 | uuid := NewUUID()
34 | if uuid != nil {
35 | uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2
36 | uuid[9] = byte(domain)
37 | binary.BigEndian.PutUint32(uuid[0:], id)
38 | }
39 | return uuid
40 | }
41 |
42 | // NewDCEPerson returns a DCE Security (Version 2) UUID in the person
43 | // domain with the id returned by os.Getuid.
44 | //
45 | // NewDCEPerson(Person, uint32(os.Getuid()))
46 | func NewDCEPerson() UUID {
47 | return NewDCESecurity(Person, uint32(os.Getuid()))
48 | }
49 |
50 | // NewDCEGroup returns a DCE Security (Version 2) UUID in the group
51 | // domain with the id returned by os.Getgid.
52 | //
53 | // NewDCEGroup(Group, uint32(os.Getgid()))
54 | func NewDCEGroup() UUID {
55 | return NewDCESecurity(Group, uint32(os.Getgid()))
56 | }
57 |
58 | // Domain returns the domain for a Version 2 UUID or false.
59 | func (uuid UUID) Domain() (Domain, bool) {
60 | if v, _ := uuid.Version(); v != 2 {
61 | return 0, false
62 | }
63 | return Domain(uuid[9]), true
64 | }
65 |
66 | // Id returns the id for a Version 2 UUID or false.
67 | func (uuid UUID) Id() (uint32, bool) {
68 | if v, _ := uuid.Version(); v != 2 {
69 | return 0, false
70 | }
71 | return binary.BigEndian.Uint32(uuid[0:4]), true
72 | }
73 |
74 | func (d Domain) String() string {
75 | switch d {
76 | case Person:
77 | return "Person"
78 | case Group:
79 | return "Group"
80 | case Org:
81 | return "Org"
82 | }
83 | return fmt.Sprintf("Domain%d", int(d))
84 | }
85 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // The uuid package generates and inspects UUIDs.
6 | //
7 | // UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services.
8 | package uuid
9 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/hash.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | import (
8 | "crypto/md5"
9 | "crypto/sha1"
10 | "hash"
11 | )
12 |
13 | // Well known Name Space IDs and UUIDs
14 | var (
15 | NameSpace_DNS = Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
16 | NameSpace_URL = Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
17 | NameSpace_OID = Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
18 | NameSpace_X500 = Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
19 | NIL = Parse("00000000-0000-0000-0000-000000000000")
20 | )
21 |
22 | // NewHash returns a new UUID derived from the hash of space concatenated with
23 | // data generated by h. The hash should be at least 16 byte in length. The
24 | // first 16 bytes of the hash are used to form the UUID. The version of the
25 | // UUID will be the lower 4 bits of version. NewHash is used to implement
26 | // NewMD5 and NewSHA1.
27 | func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
28 | h.Reset()
29 | h.Write(space)
30 | h.Write([]byte(data))
31 | s := h.Sum(nil)
32 | uuid := make([]byte, 16)
33 | copy(uuid, s)
34 | uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)
35 | uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant
36 | return uuid
37 | }
38 |
39 | // NewMD5 returns a new MD5 (Version 3) UUID based on the
40 | // supplied name space and data.
41 | //
42 | // NewHash(md5.New(), space, data, 3)
43 | func NewMD5(space UUID, data []byte) UUID {
44 | return NewHash(md5.New(), space, data, 3)
45 | }
46 |
47 | // NewSHA1 returns a new SHA1 (Version 5) UUID based on the
48 | // supplied name space and data.
49 | //
50 | // NewHash(sha1.New(), space, data, 5)
51 | func NewSHA1(space UUID, data []byte) UUID {
52 | return NewHash(sha1.New(), space, data, 5)
53 | }
54 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/json.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | import "errors"
8 |
9 | func (u UUID) MarshalJSON() ([]byte, error) {
10 | if len(u) != 16 {
11 | return []byte(`""`), nil
12 | }
13 | var js [38]byte
14 | js[0] = '"'
15 | encodeHex(js[1:], u)
16 | js[37] = '"'
17 | return js[:], nil
18 | }
19 |
20 | func (u *UUID) UnmarshalJSON(data []byte) error {
21 | if string(data) == `""` {
22 | return nil
23 | }
24 | if data[0] != '"' {
25 | return errors.New("invalid UUID format")
26 | }
27 | data = data[1 : len(data)-1]
28 | uu := Parse(string(data))
29 | if uu == nil {
30 | return errors.New("invalid UUID format")
31 | }
32 | *u = uu
33 | return nil
34 | }
35 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/node.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | import (
8 | "net"
9 | "sync"
10 | )
11 |
12 | var (
13 | nodeMu sync.Mutex
14 | interfaces []net.Interface // cached list of interfaces
15 | ifname string // name of interface being used
16 | nodeID []byte // hardware for version 1 UUIDs
17 | )
18 |
19 | // NodeInterface returns the name of the interface from which the NodeID was
20 | // derived. The interface "user" is returned if the NodeID was set by
21 | // SetNodeID.
22 | func NodeInterface() string {
23 | defer nodeMu.Unlock()
24 | nodeMu.Lock()
25 | return ifname
26 | }
27 |
28 | // SetNodeInterface selects the hardware address to be used for Version 1 UUIDs.
29 | // If name is "" then the first usable interface found will be used or a random
30 | // Node ID will be generated. If a named interface cannot be found then false
31 | // is returned.
32 | //
33 | // SetNodeInterface never fails when name is "".
34 | func SetNodeInterface(name string) bool {
35 | defer nodeMu.Unlock()
36 | nodeMu.Lock()
37 | return setNodeInterface(name)
38 | }
39 |
40 | func setNodeInterface(name string) bool {
41 | if interfaces == nil {
42 | var err error
43 | interfaces, err = net.Interfaces()
44 | if err != nil && name != "" {
45 | return false
46 | }
47 | }
48 |
49 | for _, ifs := range interfaces {
50 | if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
51 | if setNodeID(ifs.HardwareAddr) {
52 | ifname = ifs.Name
53 | return true
54 | }
55 | }
56 | }
57 |
58 | // We found no interfaces with a valid hardware address. If name
59 | // does not specify a specific interface generate a random Node ID
60 | // (section 4.1.6)
61 | if name == "" {
62 | if nodeID == nil {
63 | nodeID = make([]byte, 6)
64 | }
65 | randomBits(nodeID)
66 | return true
67 | }
68 | return false
69 | }
70 |
71 | // NodeID returns a slice of a copy of the current Node ID, setting the Node ID
72 | // if not already set.
73 | func NodeID() []byte {
74 | defer nodeMu.Unlock()
75 | nodeMu.Lock()
76 | if nodeID == nil {
77 | setNodeInterface("")
78 | }
79 | nid := make([]byte, 6)
80 | copy(nid, nodeID)
81 | return nid
82 | }
83 |
84 | // SetNodeID sets the Node ID to be used for Version 1 UUIDs. The first 6 bytes
85 | // of id are used. If id is less than 6 bytes then false is returned and the
86 | // Node ID is not set.
87 | func SetNodeID(id []byte) bool {
88 | defer nodeMu.Unlock()
89 | nodeMu.Lock()
90 | if setNodeID(id) {
91 | ifname = "user"
92 | return true
93 | }
94 | return false
95 | }
96 |
97 | func setNodeID(id []byte) bool {
98 | if len(id) < 6 {
99 | return false
100 | }
101 | if nodeID == nil {
102 | nodeID = make([]byte, 6)
103 | }
104 | copy(nodeID, id)
105 | return true
106 | }
107 |
108 | // NodeID returns the 6 byte node id encoded in uuid. It returns nil if uuid is
109 | // not valid. The NodeID is only well defined for version 1 and 2 UUIDs.
110 | func (uuid UUID) NodeID() []byte {
111 | if len(uuid) != 16 {
112 | return nil
113 | }
114 | node := make([]byte, 6)
115 | copy(node, uuid[10:])
116 | return node
117 | }
118 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/sql.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | import (
8 | "database/sql/driver"
9 | "errors"
10 | "fmt"
11 | )
12 |
13 | // Scan implements sql.Scanner so UUIDs can be read from databases transparently
14 | // Currently, database types that map to string and []byte are supported. Please
15 | // consult database-specific driver documentation for matching types.
16 | func (uuid *UUID) Scan(src interface{}) error {
17 | switch src.(type) {
18 | case string:
19 | // if an empty UUID comes from a table, we return a null UUID
20 | if src.(string) == "" {
21 | return nil
22 | }
23 |
24 | // see uuid.Parse for required string format
25 | parsed := Parse(src.(string))
26 |
27 | if parsed == nil {
28 | return errors.New("Scan: invalid UUID format")
29 | }
30 |
31 | *uuid = parsed
32 | case []byte:
33 | b := src.([]byte)
34 |
35 | // if an empty UUID comes from a table, we return a null UUID
36 | if len(b) == 0 {
37 | return nil
38 | }
39 |
40 | // assumes a simple slice of bytes if 16 bytes
41 | // otherwise attempts to parse
42 | if len(b) == 16 {
43 | *uuid = UUID(b)
44 | } else {
45 | u := Parse(string(b))
46 |
47 | if u == nil {
48 | return errors.New("Scan: invalid UUID format")
49 | }
50 |
51 | *uuid = u
52 | }
53 |
54 | default:
55 | return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
56 | }
57 |
58 | return nil
59 | }
60 |
61 | // Value implements sql.Valuer so that UUIDs can be written to databases
62 | // transparently. Currently, UUIDs map to strings. Please consult
63 | // database-specific driver documentation for matching types.
64 | func (uuid UUID) Value() (driver.Value, error) {
65 | return uuid.String(), nil
66 | }
67 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/util.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | import (
8 | "io"
9 | )
10 |
11 | // randomBits completely fills slice b with random data.
12 | func randomBits(b []byte) {
13 | if _, err := io.ReadFull(rander, b); err != nil {
14 | panic(err.Error()) // rand should never fail
15 | }
16 | }
17 |
18 | // xvalues returns the value of a byte as a hexadecimal digit or 255.
19 | var xvalues = [256]byte{
20 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
21 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
22 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
23 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
24 | 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
25 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
26 | 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
27 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
28 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
29 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
30 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
31 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
32 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
33 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
34 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
35 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
36 | }
37 |
38 | // xtob converts the the first two hex bytes of x into a byte.
39 | func xtob(x string) (byte, bool) {
40 | b1 := xvalues[x[0]]
41 | b2 := xvalues[x[1]]
42 | return (b1 << 4) | b2, b1 != 255 && b2 != 255
43 | }
44 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/version1.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | import (
8 | "encoding/binary"
9 | )
10 |
11 | // NewUUID returns a Version 1 UUID based on the current NodeID and clock
12 | // sequence, and the current time. If the NodeID has not been set by SetNodeID
13 | // or SetNodeInterface then it will be set automatically. If the NodeID cannot
14 | // be set NewUUID returns nil. If clock sequence has not been set by
15 | // SetClockSequence then it will be set automatically. If GetTime fails to
16 | // return the current NewUUID returns nil.
17 | func NewUUID() UUID {
18 | if nodeID == nil {
19 | SetNodeInterface("")
20 | }
21 |
22 | now, seq, err := GetTime()
23 | if err != nil {
24 | return nil
25 | }
26 |
27 | uuid := make([]byte, 16)
28 |
29 | time_low := uint32(now & 0xffffffff)
30 | time_mid := uint16((now >> 32) & 0xffff)
31 | time_hi := uint16((now >> 48) & 0x0fff)
32 | time_hi |= 0x1000 // Version 1
33 |
34 | binary.BigEndian.PutUint32(uuid[0:], time_low)
35 | binary.BigEndian.PutUint16(uuid[4:], time_mid)
36 | binary.BigEndian.PutUint16(uuid[6:], time_hi)
37 | binary.BigEndian.PutUint16(uuid[8:], seq)
38 | copy(uuid[10:], nodeID)
39 |
40 | return uuid
41 | }
42 |
--------------------------------------------------------------------------------
/vendor/github.com/pborman/uuid/version4.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 Google Inc. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package uuid
6 |
7 | // Random returns a Random (Version 4) UUID or panics.
8 | //
9 | // The strength of the UUIDs is based on the strength of the crypto/rand
10 | // package.
11 | //
12 | // A note about uniqueness derived from from the UUID Wikipedia entry:
13 | //
14 | // Randomly generated UUIDs have 122 random bits. One's annual risk of being
15 | // hit by a meteorite is estimated to be one chance in 17 billion, that
16 | // means the probability is about 0.00000000006 (6 × 10−11),
17 | // equivalent to the odds of creating a few tens of trillions of UUIDs in a
18 | // year and having one duplicate.
19 | func NewRandom() UUID {
20 | uuid := make([]byte, 16)
21 | randomBits([]byte(uuid))
22 | uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
23 | uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10
24 | return uuid
25 | }
26 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | Dave Cheney
2 | Saulius Gurklys
3 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, Dave Cheney
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 |
6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 |
9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/README.md:
--------------------------------------------------------------------------------
1 | sftp
2 | ----
3 |
4 | The `sftp` package provides support for file system operations on remote ssh servers using the SFTP subsystem.
5 |
6 | [](https://travis-ci.org/pkg/sftp) [](http://godoc.org/github.com/pkg/sftp)
7 |
8 | usage and examples
9 | ------------------
10 |
11 | See [godoc.org/github.com/pkg/sftp](http://godoc.org/github.com/pkg/sftp) for examples and usage.
12 |
13 | The basic operation of the package mirrors the facilities of the [os](http://golang.org/pkg/os) package.
14 |
15 | The Walker interface for directory traversal is heavily inspired by Keith Rarick's [fs](http://godoc.org/github.com/kr/fs) package.
16 |
17 | roadmap
18 | -------
19 |
20 | * Currently all traffic with the server is serialized, this can be improved by allowing overlapping requests/responses.
21 | * There is way too much duplication in the Client methods. If there was an unmarshal(interface{}) method this would reduce a heap of the duplication.
22 | * Implement integration tests by talking directly to a real opensftp-server process. This shouldn't be too difficult to implement with a small refactoring to the sftp.NewClient method. These tests should be gated on an -sftp.integration test flag. _in progress_
23 |
24 | contributing
25 | ------------
26 |
27 | We welcome pull requests, bug fixes and issue reports.
28 |
29 | Before proposing a large change, first please discuss your change by raising an issue.
30 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/attrs_stubs.go:
--------------------------------------------------------------------------------
1 | // +build !cgo,!plan9 windows android
2 |
3 | package sftp
4 |
5 | import (
6 | "os"
7 | )
8 |
9 | func fileStatFromInfoOs(fi os.FileInfo, flags *uint32, fileStat *FileStat) {
10 | // todo
11 | }
12 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/attrs_unix.go:
--------------------------------------------------------------------------------
1 | // +build darwin dragonfly freebsd !android,linux netbsd openbsd solaris
2 | // +build cgo
3 |
4 | package sftp
5 |
6 | import (
7 | "os"
8 | "syscall"
9 | )
10 |
11 | func fileStatFromInfoOs(fi os.FileInfo, flags *uint32, fileStat *FileStat) {
12 | if statt, ok := fi.Sys().(*syscall.Stat_t); ok {
13 | *flags |= ssh_FILEXFER_ATTR_UIDGID
14 | fileStat.UID = statt.Uid
15 | fileStat.GID = statt.Gid
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/debug.go:
--------------------------------------------------------------------------------
1 | // +build debug
2 |
3 | package sftp
4 |
5 | import "log"
6 |
7 | func debug(fmt string, args ...interface{}) {
8 | log.Printf(fmt, args...)
9 | }
10 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/release.go:
--------------------------------------------------------------------------------
1 | // +build !debug
2 |
3 | package sftp
4 |
5 | func debug(fmt string, args ...interface{}) {}
6 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/sftp/server_stubs.go:
--------------------------------------------------------------------------------
1 | // +build !cgo,!plan9 windows android
2 |
3 | package sftp
4 |
5 | import (
6 | "os"
7 | "path"
8 | )
9 |
10 | func runLs(dirname string, dirent os.FileInfo) string {
11 | return path.Join(dirname, dirent.Name())
12 | }
13 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: '{build}'
2 | clone_folder: C:\gopath\src\github.com\spf13\afero
3 | environment:
4 | GOPATH: C:\gopath
5 | build_script:
6 | - cmd: >-
7 | go version
8 |
9 | go env
10 |
11 | go get -v github.com/spf13/afero/...
12 |
13 | go build github.com/spf13/afero
14 | test_script:
15 | - cmd: go test -v github.com/spf13/afero
16 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/const_bsds.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Steve Francia .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | // +build darwin openbsd freebsd
15 |
16 | package afero
17 |
18 | import (
19 | "syscall"
20 | )
21 |
22 | const BADFD = syscall.EBADF
23 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/const_win_unix.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2016 Steve Francia .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 | // +build !darwin
14 | // +build !openbsd
15 | // +build !freebsd
16 |
17 | package afero
18 |
19 | import (
20 | "syscall"
21 | )
22 |
23 | const BADFD = syscall.EBADFD
24 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/httpFs.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2014 Steve Francia .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package afero
15 |
16 | import (
17 | "errors"
18 | "net/http"
19 | "os"
20 | "path"
21 | "path/filepath"
22 | "strings"
23 | "time"
24 | )
25 |
26 | type httpDir struct {
27 | basePath string
28 | fs HttpFs
29 | }
30 |
31 | func (d httpDir) Open(name string) (http.File, error) {
32 | if filepath.Separator != '/' && strings.IndexRune(name, filepath.Separator) >= 0 ||
33 | strings.Contains(name, "\x00") {
34 | return nil, errors.New("http: invalid character in file path")
35 | }
36 | dir := string(d.basePath)
37 | if dir == "" {
38 | dir = "."
39 | }
40 |
41 | f, err := d.fs.Open(filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name))))
42 | if err != nil {
43 | return nil, err
44 | }
45 | return f, nil
46 | }
47 |
48 | type HttpFs struct {
49 | source Fs
50 | }
51 |
52 | func NewHttpFs(source Fs) *HttpFs {
53 | return &HttpFs{source: source}
54 | }
55 |
56 | func (h HttpFs) Dir(s string) *httpDir {
57 | return &httpDir{basePath: s, fs: h}
58 | }
59 |
60 | func (h HttpFs) Name() string { return "h HttpFs" }
61 |
62 | func (h HttpFs) Create(name string) (File, error) {
63 | return h.source.Create(name)
64 | }
65 |
66 | func (h HttpFs) Chmod(name string, mode os.FileMode) error {
67 | return h.source.Chmod(name, mode)
68 | }
69 |
70 | func (h HttpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
71 | return h.source.Chtimes(name, atime, mtime)
72 | }
73 |
74 | func (h HttpFs) Mkdir(name string, perm os.FileMode) error {
75 | return h.source.Mkdir(name, perm)
76 | }
77 |
78 | func (h HttpFs) MkdirAll(path string, perm os.FileMode) error {
79 | return h.source.MkdirAll(path, perm)
80 | }
81 |
82 | func (h HttpFs) Open(name string) (http.File, error) {
83 | f, err := h.source.Open(name)
84 | if err == nil {
85 | if httpfile, ok := f.(http.File); ok {
86 | return httpfile, nil
87 | }
88 | }
89 | return nil, err
90 | }
91 |
92 | func (h HttpFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
93 | return h.source.OpenFile(name, flag, perm)
94 | }
95 |
96 | func (h HttpFs) Remove(name string) error {
97 | return h.source.Remove(name)
98 | }
99 |
100 | func (h HttpFs) RemoveAll(path string) error {
101 | return h.source.RemoveAll(path)
102 | }
103 |
104 | func (h HttpFs) Rename(oldname, newname string) error {
105 | return h.source.Rename(oldname, newname)
106 | }
107 |
108 | func (h HttpFs) Stat(name string) (os.FileInfo, error) {
109 | return h.source.Stat(name)
110 | }
111 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/mem/dir.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2014 Steve Francia .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package mem
15 |
16 | type Dir interface {
17 | Len() int
18 | Names() []string
19 | Files() []*FileData
20 | Add(*FileData)
21 | Remove(*FileData)
22 | }
23 |
24 | func RemoveFromMemDir(dir *FileData, f *FileData) {
25 | dir.memDir.Remove(f)
26 | }
27 |
28 | func AddToMemDir(dir *FileData, f *FileData) {
29 | dir.memDir.Add(f)
30 | }
31 |
32 | func InitializeDir(d *FileData) {
33 | if d.memDir == nil {
34 | d.dir = true
35 | d.memDir = &DirMap{}
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/mem/dirmap.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2015 Steve Francia .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package mem
15 |
16 | import "sort"
17 |
18 | type DirMap map[string]*FileData
19 |
20 | func (m DirMap) Len() int { return len(m) }
21 | func (m DirMap) Add(f *FileData) { m[f.name] = f }
22 | func (m DirMap) Remove(f *FileData) { delete(m, f.name) }
23 | func (m DirMap) Files() (files []*FileData) {
24 | for _, f := range m {
25 | files = append(files, f)
26 | }
27 | sort.Sort(filesSorter(files))
28 | return files
29 | }
30 |
31 | // implement sort.Interface for []*FileData
32 | type filesSorter []*FileData
33 |
34 | func (s filesSorter) Len() int { return len(s) }
35 | func (s filesSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
36 | func (s filesSorter) Less(i, j int) bool { return s[i].name < s[j].name }
37 |
38 | func (m DirMap) Names() (names []string) {
39 | for x := range m {
40 | names = append(names, x)
41 | }
42 | return names
43 | }
44 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/memradix.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2014 Steve Francia .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package afero
15 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/os.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2014 Steve Francia .
2 | // Copyright 2013 tsuru authors. All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package afero
16 |
17 | import (
18 | "os"
19 | "time"
20 | )
21 |
22 | // OsFs is a Fs implementation that uses functions provided by the os package.
23 | //
24 | // For details in any method, check the documentation of the os package
25 | // (http://golang.org/pkg/os/).
26 | type OsFs struct{}
27 |
28 | func NewOsFs() Fs {
29 | return &OsFs{}
30 | }
31 |
32 | func (OsFs) Name() string { return "OsFs" }
33 |
34 | func (OsFs) Create(name string) (File, error) {
35 | f, e := os.Create(name)
36 | if f == nil {
37 | // while this looks strange, we need to return a bare nil (of type nil) not
38 | // a nil value of type *os.File or nil won't be nil
39 | return nil, e
40 | }
41 | return f, e
42 | }
43 |
44 | func (OsFs) Mkdir(name string, perm os.FileMode) error {
45 | return os.Mkdir(name, perm)
46 | }
47 |
48 | func (OsFs) MkdirAll(path string, perm os.FileMode) error {
49 | return os.MkdirAll(path, perm)
50 | }
51 |
52 | func (OsFs) Open(name string) (File, error) {
53 | f, e := os.Open(name)
54 | if f == nil {
55 | // while this looks strange, we need to return a bare nil (of type nil) not
56 | // a nil value of type *os.File or nil won't be nil
57 | return nil, e
58 | }
59 | return f, e
60 | }
61 |
62 | func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
63 | f, e := os.OpenFile(name, flag, perm)
64 | if f == nil {
65 | // while this looks strange, we need to return a bare nil (of type nil) not
66 | // a nil value of type *os.File or nil won't be nil
67 | return nil, e
68 | }
69 | return f, e
70 | }
71 |
72 | func (OsFs) Remove(name string) error {
73 | return os.Remove(name)
74 | }
75 |
76 | func (OsFs) RemoveAll(path string) error {
77 | return os.RemoveAll(path)
78 | }
79 |
80 | func (OsFs) Rename(oldname, newname string) error {
81 | return os.Rename(oldname, newname)
82 | }
83 |
84 | func (OsFs) Stat(name string) (os.FileInfo, error) {
85 | return os.Stat(name)
86 | }
87 |
88 | func (OsFs) Chmod(name string, mode os.FileMode) error {
89 | return os.Chmod(name, mode)
90 | }
91 |
92 | func (OsFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
93 | return os.Chtimes(name, atime, mtime)
94 | }
95 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/path.go:
--------------------------------------------------------------------------------
1 | // Copyright ©2015 The Go Authors
2 | // Copyright ©2015 Steve Francia
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 |
16 | package afero
17 |
18 | import (
19 | "os"
20 | "path/filepath"
21 | "sort"
22 | )
23 |
24 | // readDirNames reads the directory named by dirname and returns
25 | // a sorted list of directory entries.
26 | // adapted from https://golang.org/src/path/filepath/path.go
27 | func readDirNames(fs Fs, dirname string) ([]string, error) {
28 | f, err := fs.Open(dirname)
29 | if err != nil {
30 | return nil, err
31 | }
32 | names, err := f.Readdirnames(-1)
33 | f.Close()
34 | if err != nil {
35 | return nil, err
36 | }
37 | sort.Strings(names)
38 | return names, nil
39 | }
40 |
41 | // walk recursively descends path, calling walkFn
42 | // adapted from https://golang.org/src/path/filepath/path.go
43 | func walk(fs Fs, path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
44 | err := walkFn(path, info, nil)
45 | if err != nil {
46 | if info.IsDir() && err == filepath.SkipDir {
47 | return nil
48 | }
49 | return err
50 | }
51 |
52 | if !info.IsDir() {
53 | return nil
54 | }
55 |
56 | names, err := readDirNames(fs, path)
57 | if err != nil {
58 | return walkFn(path, info, err)
59 | }
60 |
61 | for _, name := range names {
62 | filename := filepath.Join(path, name)
63 | fileInfo, err := lstatIfOs(fs, filename)
64 | if err != nil {
65 | if err := walkFn(filename, fileInfo, err); err != nil && err != filepath.SkipDir {
66 | return err
67 | }
68 | } else {
69 | err = walk(fs, filename, fileInfo, walkFn)
70 | if err != nil {
71 | if !fileInfo.IsDir() || err != filepath.SkipDir {
72 | return err
73 | }
74 | }
75 | }
76 | }
77 | return nil
78 | }
79 |
80 | // if the filesystem is OsFs use Lstat, else use fs.Stat
81 | func lstatIfOs(fs Fs, path string) (info os.FileInfo, err error) {
82 | _, ok := fs.(*OsFs)
83 | if ok {
84 | info, err = os.Lstat(path)
85 | } else {
86 | info, err = fs.Stat(path)
87 | }
88 | return
89 | }
90 |
91 | // Walk walks the file tree rooted at root, calling walkFn for each file or
92 | // directory in the tree, including root. All errors that arise visiting files
93 | // and directories are filtered by walkFn. The files are walked in lexical
94 | // order, which makes the output deterministic but means that for very
95 | // large directories Walk can be inefficient.
96 | // Walk does not follow symbolic links.
97 |
98 | func (a Afero) Walk(root string, walkFn filepath.WalkFunc) error {
99 | return Walk(a.Fs, root, walkFn)
100 | }
101 |
102 | func Walk(fs Fs, root string, walkFn filepath.WalkFunc) error {
103 | info, err := lstatIfOs(fs, root)
104 | if err != nil {
105 | return walkFn(root, nil, err)
106 | }
107 | return walk(fs, root, info, walkFn)
108 | }
109 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/readonlyfs.go:
--------------------------------------------------------------------------------
1 | package afero
2 |
3 | import (
4 | "os"
5 | "syscall"
6 | "time"
7 | )
8 |
9 | type ReadOnlyFs struct {
10 | source Fs
11 | }
12 |
13 | func NewReadOnlyFs(source Fs) Fs {
14 | return &ReadOnlyFs{source: source}
15 | }
16 |
17 | func (r *ReadOnlyFs) ReadDir(name string) ([]os.FileInfo, error) {
18 | return ReadDir(r.source, name)
19 | }
20 |
21 | func (r *ReadOnlyFs) Chtimes(n string, a, m time.Time) error {
22 | return syscall.EPERM
23 | }
24 |
25 | func (r *ReadOnlyFs) Chmod(n string, m os.FileMode) error {
26 | return syscall.EPERM
27 | }
28 |
29 | func (r *ReadOnlyFs) Name() string {
30 | return "ReadOnlyFilter"
31 | }
32 |
33 | func (r *ReadOnlyFs) Stat(name string) (os.FileInfo, error) {
34 | return r.source.Stat(name)
35 | }
36 |
37 | func (r *ReadOnlyFs) Rename(o, n string) error {
38 | return syscall.EPERM
39 | }
40 |
41 | func (r *ReadOnlyFs) RemoveAll(p string) error {
42 | return syscall.EPERM
43 | }
44 |
45 | func (r *ReadOnlyFs) Remove(n string) error {
46 | return syscall.EPERM
47 | }
48 |
49 | func (r *ReadOnlyFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
50 | if flag&(os.O_WRONLY|syscall.O_RDWR|os.O_APPEND|os.O_CREATE|os.O_TRUNC) != 0 {
51 | return nil, syscall.EPERM
52 | }
53 | return r.source.OpenFile(name, flag, perm)
54 | }
55 |
56 | func (r *ReadOnlyFs) Open(n string) (File, error) {
57 | return r.source.Open(n)
58 | }
59 |
60 | func (r *ReadOnlyFs) Mkdir(n string, p os.FileMode) error {
61 | return syscall.EPERM
62 | }
63 |
64 | func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error {
65 | return syscall.EPERM
66 | }
67 |
68 | func (r *ReadOnlyFs) Create(n string) (File, error) {
69 | return nil, syscall.EPERM
70 | }
71 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/afero/sftp/file.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2015 Jerry Jacobs .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | package sftpfs
15 |
16 | import (
17 | "os"
18 | "github.com/pkg/sftp"
19 | )
20 |
21 | type File struct {
22 | fd *sftp.File
23 | }
24 |
25 | func FileOpen(s *sftp.Client, name string) (*File, error) {
26 | fd, err := s.Open(name)
27 | if err != nil {
28 | return &File{}, err
29 | }
30 | return &File{fd: fd}, nil
31 | }
32 |
33 | func FileCreate(s *sftp.Client, name string) (*File, error) {
34 | fd, err := s.Create(name)
35 | if err != nil {
36 | return &File{}, err
37 | }
38 | return &File{fd: fd}, nil
39 | }
40 |
41 | func (f *File) Close() error {
42 | return f.fd.Close()
43 | }
44 |
45 | func (f *File) Name() string {
46 | return f.fd.Name()
47 | }
48 |
49 | func (f *File) Stat() (os.FileInfo, error) {
50 | return f.fd.Stat()
51 | }
52 |
53 | func (f *File) Sync() error {
54 | return nil
55 | }
56 |
57 | func (f *File) Truncate(size int64) error {
58 | return f.fd.Truncate(size)
59 | }
60 |
61 | func (f *File) Read(b []byte) (n int, err error) {
62 | return f.fd.Read(b)
63 | }
64 |
65 | // TODO
66 | func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
67 | return 0,nil
68 | }
69 |
70 | // TODO
71 | func (f *File) Readdir(count int) (res []os.FileInfo, err error) {
72 | return nil,nil
73 | }
74 |
75 | // TODO
76 | func (f *File) Readdirnames(n int) (names []string, err error) {
77 | return nil,nil
78 | }
79 |
80 | func (f *File) Seek(offset int64, whence int) (int64, error) {
81 | return f.fd.Seek(offset, whence)
82 | }
83 |
84 | func (f *File) Write(b []byte) (n int, err error) {
85 | return f.fd.Write(b)
86 | }
87 |
88 | // TODO
89 | func (f *File) WriteAt(b []byte, off int64) (n int, err error) {
90 | return 0,nil
91 | }
92 |
93 | func (f *File) WriteString(s string) (ret int, err error) {
94 | return f.fd.Write([]byte(s))
95 | }
96 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/curve25519/const_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | DATA ·REDMASK51(SB)/8, $0x0007FFFFFFFFFFFF
11 | GLOBL ·REDMASK51(SB), 8, $8
12 |
13 | DATA ·_121666_213(SB)/8, $996687872
14 | GLOBL ·_121666_213(SB), 8, $8
15 |
16 | DATA ·_2P0(SB)/8, $0xFFFFFFFFFFFDA
17 | GLOBL ·_2P0(SB), 8, $8
18 |
19 | DATA ·_2P1234(SB)/8, $0xFFFFFFFFFFFFE
20 | GLOBL ·_2P1234(SB), 8, $8
21 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/curve25519/cswap_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | // func cswap(inout *[5]uint64, v uint64)
11 | TEXT ·cswap(SB),7,$0
12 | MOVQ inout+0(FP),DI
13 | MOVQ v+8(FP),SI
14 |
15 | CMPQ SI,$1
16 | MOVQ 0(DI),SI
17 | MOVQ 80(DI),DX
18 | MOVQ 8(DI),CX
19 | MOVQ 88(DI),R8
20 | MOVQ SI,R9
21 | CMOVQEQ DX,SI
22 | CMOVQEQ R9,DX
23 | MOVQ CX,R9
24 | CMOVQEQ R8,CX
25 | CMOVQEQ R9,R8
26 | MOVQ SI,0(DI)
27 | MOVQ DX,80(DI)
28 | MOVQ CX,8(DI)
29 | MOVQ R8,88(DI)
30 | MOVQ 16(DI),SI
31 | MOVQ 96(DI),DX
32 | MOVQ 24(DI),CX
33 | MOVQ 104(DI),R8
34 | MOVQ SI,R9
35 | CMOVQEQ DX,SI
36 | CMOVQEQ R9,DX
37 | MOVQ CX,R9
38 | CMOVQEQ R8,CX
39 | CMOVQEQ R9,R8
40 | MOVQ SI,16(DI)
41 | MOVQ DX,96(DI)
42 | MOVQ CX,24(DI)
43 | MOVQ R8,104(DI)
44 | MOVQ 32(DI),SI
45 | MOVQ 112(DI),DX
46 | MOVQ 40(DI),CX
47 | MOVQ 120(DI),R8
48 | MOVQ SI,R9
49 | CMOVQEQ DX,SI
50 | CMOVQEQ R9,DX
51 | MOVQ CX,R9
52 | CMOVQEQ R8,CX
53 | CMOVQEQ R9,R8
54 | MOVQ SI,32(DI)
55 | MOVQ DX,112(DI)
56 | MOVQ CX,40(DI)
57 | MOVQ R8,120(DI)
58 | MOVQ 48(DI),SI
59 | MOVQ 128(DI),DX
60 | MOVQ 56(DI),CX
61 | MOVQ 136(DI),R8
62 | MOVQ SI,R9
63 | CMOVQEQ DX,SI
64 | CMOVQEQ R9,DX
65 | MOVQ CX,R9
66 | CMOVQEQ R8,CX
67 | CMOVQEQ R9,R8
68 | MOVQ SI,48(DI)
69 | MOVQ DX,128(DI)
70 | MOVQ CX,56(DI)
71 | MOVQ R8,136(DI)
72 | MOVQ 64(DI),SI
73 | MOVQ 144(DI),DX
74 | MOVQ 72(DI),CX
75 | MOVQ 152(DI),R8
76 | MOVQ SI,R9
77 | CMOVQEQ DX,SI
78 | CMOVQEQ R9,DX
79 | MOVQ CX,R9
80 | CMOVQEQ R8,CX
81 | CMOVQEQ R9,R8
82 | MOVQ SI,64(DI)
83 | MOVQ DX,144(DI)
84 | MOVQ CX,72(DI)
85 | MOVQ R8,152(DI)
86 | MOVQ DI,AX
87 | MOVQ SI,DX
88 | RET
89 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/curve25519/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package curve25519 provides an implementation of scalar multiplication on
6 | // the elliptic curve known as curve25519. See http://cr.yp.to/ecdh.html
7 | package curve25519 // import "golang.org/x/crypto/curve25519"
8 |
9 | // basePoint is the x coordinate of the generator of the curve.
10 | var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
11 |
12 | // ScalarMult sets dst to the product in*base where dst and base are the x
13 | // coordinates of group points and all values are in little-endian form.
14 | func ScalarMult(dst, in, base *[32]byte) {
15 | scalarMult(dst, in, base)
16 | }
17 |
18 | // ScalarBaseMult sets dst to the product in*base where dst and base are the x
19 | // coordinates of group points, base is the standard generator and all values
20 | // are in little-endian form.
21 | func ScalarBaseMult(dst, in *[32]byte) {
22 | ScalarMult(dst, in, &basePoint)
23 | }
24 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/curve25519/freeze_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | // func freeze(inout *[5]uint64)
11 | TEXT ·freeze(SB),7,$96-8
12 | MOVQ inout+0(FP), DI
13 |
14 | MOVQ SP,R11
15 | MOVQ $31,CX
16 | NOTQ CX
17 | ANDQ CX,SP
18 | ADDQ $32,SP
19 |
20 | MOVQ R11,0(SP)
21 | MOVQ R12,8(SP)
22 | MOVQ R13,16(SP)
23 | MOVQ R14,24(SP)
24 | MOVQ R15,32(SP)
25 | MOVQ BX,40(SP)
26 | MOVQ BP,48(SP)
27 | MOVQ 0(DI),SI
28 | MOVQ 8(DI),DX
29 | MOVQ 16(DI),CX
30 | MOVQ 24(DI),R8
31 | MOVQ 32(DI),R9
32 | MOVQ ·REDMASK51(SB),AX
33 | MOVQ AX,R10
34 | SUBQ $18,R10
35 | MOVQ $3,R11
36 | REDUCELOOP:
37 | MOVQ SI,R12
38 | SHRQ $51,R12
39 | ANDQ AX,SI
40 | ADDQ R12,DX
41 | MOVQ DX,R12
42 | SHRQ $51,R12
43 | ANDQ AX,DX
44 | ADDQ R12,CX
45 | MOVQ CX,R12
46 | SHRQ $51,R12
47 | ANDQ AX,CX
48 | ADDQ R12,R8
49 | MOVQ R8,R12
50 | SHRQ $51,R12
51 | ANDQ AX,R8
52 | ADDQ R12,R9
53 | MOVQ R9,R12
54 | SHRQ $51,R12
55 | ANDQ AX,R9
56 | IMUL3Q $19,R12,R12
57 | ADDQ R12,SI
58 | SUBQ $1,R11
59 | JA REDUCELOOP
60 | MOVQ $1,R12
61 | CMPQ R10,SI
62 | CMOVQLT R11,R12
63 | CMPQ AX,DX
64 | CMOVQNE R11,R12
65 | CMPQ AX,CX
66 | CMOVQNE R11,R12
67 | CMPQ AX,R8
68 | CMOVQNE R11,R12
69 | CMPQ AX,R9
70 | CMOVQNE R11,R12
71 | NEGQ R12
72 | ANDQ R12,AX
73 | ANDQ R12,R10
74 | SUBQ R10,SI
75 | SUBQ AX,DX
76 | SUBQ AX,CX
77 | SUBQ AX,R8
78 | SUBQ AX,R9
79 | MOVQ SI,0(DI)
80 | MOVQ DX,8(DI)
81 | MOVQ CX,16(DI)
82 | MOVQ R8,24(DI)
83 | MOVQ R9,32(DI)
84 | MOVQ 0(SP),R11
85 | MOVQ 8(SP),R12
86 | MOVQ 16(SP),R13
87 | MOVQ 24(SP),R14
88 | MOVQ 32(SP),R15
89 | MOVQ 40(SP),BX
90 | MOVQ 48(SP),BP
91 | MOVQ R11,SP
92 | MOVQ DI,AX
93 | MOVQ SI,DX
94 | RET
95 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/curve25519/square_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | // func square(out, in *[5]uint64)
11 | TEXT ·square(SB),7,$96-16
12 | MOVQ out+0(FP), DI
13 | MOVQ in+8(FP), SI
14 |
15 | MOVQ SP,R11
16 | MOVQ $31,CX
17 | NOTQ CX
18 | ANDQ CX,SP
19 | ADDQ $32, SP
20 |
21 | MOVQ R11,0(SP)
22 | MOVQ R12,8(SP)
23 | MOVQ R13,16(SP)
24 | MOVQ R14,24(SP)
25 | MOVQ R15,32(SP)
26 | MOVQ BX,40(SP)
27 | MOVQ BP,48(SP)
28 | MOVQ 0(SI),AX
29 | MULQ 0(SI)
30 | MOVQ AX,CX
31 | MOVQ DX,R8
32 | MOVQ 0(SI),AX
33 | SHLQ $1,AX
34 | MULQ 8(SI)
35 | MOVQ AX,R9
36 | MOVQ DX,R10
37 | MOVQ 0(SI),AX
38 | SHLQ $1,AX
39 | MULQ 16(SI)
40 | MOVQ AX,R11
41 | MOVQ DX,R12
42 | MOVQ 0(SI),AX
43 | SHLQ $1,AX
44 | MULQ 24(SI)
45 | MOVQ AX,R13
46 | MOVQ DX,R14
47 | MOVQ 0(SI),AX
48 | SHLQ $1,AX
49 | MULQ 32(SI)
50 | MOVQ AX,R15
51 | MOVQ DX,BX
52 | MOVQ 8(SI),AX
53 | MULQ 8(SI)
54 | ADDQ AX,R11
55 | ADCQ DX,R12
56 | MOVQ 8(SI),AX
57 | SHLQ $1,AX
58 | MULQ 16(SI)
59 | ADDQ AX,R13
60 | ADCQ DX,R14
61 | MOVQ 8(SI),AX
62 | SHLQ $1,AX
63 | MULQ 24(SI)
64 | ADDQ AX,R15
65 | ADCQ DX,BX
66 | MOVQ 8(SI),DX
67 | IMUL3Q $38,DX,AX
68 | MULQ 32(SI)
69 | ADDQ AX,CX
70 | ADCQ DX,R8
71 | MOVQ 16(SI),AX
72 | MULQ 16(SI)
73 | ADDQ AX,R15
74 | ADCQ DX,BX
75 | MOVQ 16(SI),DX
76 | IMUL3Q $38,DX,AX
77 | MULQ 24(SI)
78 | ADDQ AX,CX
79 | ADCQ DX,R8
80 | MOVQ 16(SI),DX
81 | IMUL3Q $38,DX,AX
82 | MULQ 32(SI)
83 | ADDQ AX,R9
84 | ADCQ DX,R10
85 | MOVQ 24(SI),DX
86 | IMUL3Q $19,DX,AX
87 | MULQ 24(SI)
88 | ADDQ AX,R9
89 | ADCQ DX,R10
90 | MOVQ 24(SI),DX
91 | IMUL3Q $38,DX,AX
92 | MULQ 32(SI)
93 | ADDQ AX,R11
94 | ADCQ DX,R12
95 | MOVQ 32(SI),DX
96 | IMUL3Q $19,DX,AX
97 | MULQ 32(SI)
98 | ADDQ AX,R13
99 | ADCQ DX,R14
100 | MOVQ ·REDMASK51(SB),SI
101 | SHLQ $13,R8:CX
102 | ANDQ SI,CX
103 | SHLQ $13,R10:R9
104 | ANDQ SI,R9
105 | ADDQ R8,R9
106 | SHLQ $13,R12:R11
107 | ANDQ SI,R11
108 | ADDQ R10,R11
109 | SHLQ $13,R14:R13
110 | ANDQ SI,R13
111 | ADDQ R12,R13
112 | SHLQ $13,BX:R15
113 | ANDQ SI,R15
114 | ADDQ R14,R15
115 | IMUL3Q $19,BX,DX
116 | ADDQ DX,CX
117 | MOVQ CX,DX
118 | SHRQ $51,DX
119 | ADDQ R9,DX
120 | ANDQ SI,CX
121 | MOVQ DX,R8
122 | SHRQ $51,DX
123 | ADDQ R11,DX
124 | ANDQ SI,R8
125 | MOVQ DX,R9
126 | SHRQ $51,DX
127 | ADDQ R13,DX
128 | ANDQ SI,R9
129 | MOVQ DX,AX
130 | SHRQ $51,DX
131 | ADDQ R15,DX
132 | ANDQ SI,AX
133 | MOVQ DX,R10
134 | SHRQ $51,DX
135 | IMUL3Q $19,DX,DX
136 | ADDQ DX,CX
137 | ANDQ SI,R10
138 | MOVQ CX,0(DI)
139 | MOVQ R8,8(DI)
140 | MOVQ R9,16(DI)
141 | MOVQ AX,24(DI)
142 | MOVQ R10,32(DI)
143 | MOVQ 0(SP),R11
144 | MOVQ 8(SP),R12
145 | MOVQ 16(SP),R13
146 | MOVQ 24(SP),R14
147 | MOVQ 32(SP),R15
148 | MOVQ 40(SP),BX
149 | MOVQ 48(SP),BP
150 | MOVQ R11,SP
151 | MOVQ DI,AX
152 | MOVQ SI,DX
153 | RET
154 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/ssh/buffer.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ssh
6 |
7 | import (
8 | "io"
9 | "sync"
10 | )
11 |
12 | // buffer provides a linked list buffer for data exchange
13 | // between producer and consumer. Theoretically the buffer is
14 | // of unlimited capacity as it does no allocation of its own.
15 | type buffer struct {
16 | // protects concurrent access to head, tail and closed
17 | *sync.Cond
18 |
19 | head *element // the buffer that will be read first
20 | tail *element // the buffer that will be read last
21 |
22 | closed bool
23 | }
24 |
25 | // An element represents a single link in a linked list.
26 | type element struct {
27 | buf []byte
28 | next *element
29 | }
30 |
31 | // newBuffer returns an empty buffer that is not closed.
32 | func newBuffer() *buffer {
33 | e := new(element)
34 | b := &buffer{
35 | Cond: newCond(),
36 | head: e,
37 | tail: e,
38 | }
39 | return b
40 | }
41 |
42 | // write makes buf available for Read to receive.
43 | // buf must not be modified after the call to write.
44 | func (b *buffer) write(buf []byte) {
45 | b.Cond.L.Lock()
46 | e := &element{buf: buf}
47 | b.tail.next = e
48 | b.tail = e
49 | b.Cond.Signal()
50 | b.Cond.L.Unlock()
51 | }
52 |
53 | // eof closes the buffer. Reads from the buffer once all
54 | // the data has been consumed will receive os.EOF.
55 | func (b *buffer) eof() error {
56 | b.Cond.L.Lock()
57 | b.closed = true
58 | b.Cond.Signal()
59 | b.Cond.L.Unlock()
60 | return nil
61 | }
62 |
63 | // Read reads data from the internal buffer in buf. Reads will block
64 | // if no data is available, or until the buffer is closed.
65 | func (b *buffer) Read(buf []byte) (n int, err error) {
66 | b.Cond.L.Lock()
67 | defer b.Cond.L.Unlock()
68 |
69 | for len(buf) > 0 {
70 | // if there is data in b.head, copy it
71 | if len(b.head.buf) > 0 {
72 | r := copy(buf, b.head.buf)
73 | buf, b.head.buf = buf[r:], b.head.buf[r:]
74 | n += r
75 | continue
76 | }
77 | // if there is a next buffer, make it the head
78 | if len(b.head.buf) == 0 && b.head != b.tail {
79 | b.head = b.head.next
80 | continue
81 | }
82 |
83 | // if at least one byte has been copied, return
84 | if n > 0 {
85 | break
86 | }
87 |
88 | // if nothing was read, and there is nothing outstanding
89 | // check to see if the buffer is closed.
90 | if b.closed {
91 | err = io.EOF
92 | break
93 | }
94 | // out of buffers, wait for producer
95 | b.Cond.Wait()
96 | }
97 | return
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/ssh/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | Package ssh implements an SSH client and server.
7 |
8 | SSH is a transport security protocol, an authentication protocol and a
9 | family of application protocols. The most typical application level
10 | protocol is a remote shell and this is specifically implemented. However,
11 | the multiplexed nature of SSH is exposed to users that wish to support
12 | others.
13 |
14 | References:
15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
17 | */
18 | package ssh // import "golang.org/x/crypto/ssh"
19 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/ssh/mac.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ssh
6 |
7 | // Message authentication support
8 |
9 | import (
10 | "crypto/hmac"
11 | "crypto/sha1"
12 | "crypto/sha256"
13 | "hash"
14 | )
15 |
16 | type macMode struct {
17 | keySize int
18 | new func(key []byte) hash.Hash
19 | }
20 |
21 | // truncatingMAC wraps around a hash.Hash and truncates the output digest to
22 | // a given size.
23 | type truncatingMAC struct {
24 | length int
25 | hmac hash.Hash
26 | }
27 |
28 | func (t truncatingMAC) Write(data []byte) (int, error) {
29 | return t.hmac.Write(data)
30 | }
31 |
32 | func (t truncatingMAC) Sum(in []byte) []byte {
33 | out := t.hmac.Sum(in)
34 | return out[:len(in)+t.length]
35 | }
36 |
37 | func (t truncatingMAC) Reset() {
38 | t.hmac.Reset()
39 | }
40 |
41 | func (t truncatingMAC) Size() int {
42 | return t.length
43 | }
44 |
45 | func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() }
46 |
47 | var macModes = map[string]*macMode{
48 | "hmac-sha2-256": {32, func(key []byte) hash.Hash {
49 | return hmac.New(sha256.New, key)
50 | }},
51 | "hmac-sha1": {20, func(key []byte) hash.Hash {
52 | return hmac.New(sha1.New, key)
53 | }},
54 | "hmac-sha1-96": {20, func(key []byte) hash.Hash {
55 | return truncatingMAC{12, hmac.New(sha1.New, key)}
56 | }},
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/html/atom/atom.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package atom provides integer codes (also known as atoms) for a fixed set of
6 | // frequently occurring HTML strings: tag names and attribute keys such as "p"
7 | // and "id".
8 | //
9 | // Sharing an atom's name between all elements with the same tag can result in
10 | // fewer string allocations when tokenizing and parsing HTML. Integer
11 | // comparisons are also generally faster than string comparisons.
12 | //
13 | // The value of an atom's particular code is not guaranteed to stay the same
14 | // between versions of this package. Neither is any ordering guaranteed:
15 | // whether atom.H1 < atom.H2 may also change. The codes are not guaranteed to
16 | // be dense. The only guarantees are that e.g. looking up "div" will yield
17 | // atom.Div, calling atom.Div.String will return "div", and atom.Div != 0.
18 | package atom // import "golang.org/x/net/html/atom"
19 |
20 | // Atom is an integer code for a string. The zero value maps to "".
21 | type Atom uint32
22 |
23 | // String returns the atom's name.
24 | func (a Atom) String() string {
25 | start := uint32(a >> 8)
26 | n := uint32(a & 0xff)
27 | if start+n > uint32(len(atomText)) {
28 | return ""
29 | }
30 | return atomText[start : start+n]
31 | }
32 |
33 | func (a Atom) string() string {
34 | return atomText[a>>8 : a>>8+a&0xff]
35 | }
36 |
37 | // fnv computes the FNV hash with an arbitrary starting value h.
38 | func fnv(h uint32, s []byte) uint32 {
39 | for i := range s {
40 | h ^= uint32(s[i])
41 | h *= 16777619
42 | }
43 | return h
44 | }
45 |
46 | func match(s string, t []byte) bool {
47 | for i, c := range t {
48 | if s[i] != c {
49 | return false
50 | }
51 | }
52 | return true
53 | }
54 |
55 | // Lookup returns the atom whose name is s. It returns zero if there is no
56 | // such atom. The lookup is case sensitive.
57 | func Lookup(s []byte) Atom {
58 | if len(s) == 0 || len(s) > maxAtomLen {
59 | return 0
60 | }
61 | h := fnv(hash0, s)
62 | if a := table[h&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) {
63 | return a
64 | }
65 | if a := table[(h>>16)&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) {
66 | return a
67 | }
68 | return 0
69 | }
70 |
71 | // String returns a string whose contents are equal to s. In that sense, it is
72 | // equivalent to string(s) but may be more efficient.
73 | func String(s []byte) string {
74 | if a := Lookup(s); a != 0 {
75 | return a.String()
76 | }
77 | return string(s)
78 | }
79 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/net/html/const.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package html
6 |
7 | // Section 12.2.3.2 of the HTML5 specification says "The following elements
8 | // have varying levels of special parsing rules".
9 | // https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-open-elements
10 | var isSpecialElementMap = map[string]bool{
11 | "address": true,
12 | "applet": true,
13 | "area": true,
14 | "article": true,
15 | "aside": true,
16 | "base": true,
17 | "basefont": true,
18 | "bgsound": true,
19 | "blockquote": true,
20 | "body": true,
21 | "br": true,
22 | "button": true,
23 | "caption": true,
24 | "center": true,
25 | "col": true,
26 | "colgroup": true,
27 | "dd": true,
28 | "details": true,
29 | "dir": true,
30 | "div": true,
31 | "dl": true,
32 | "dt": true,
33 | "embed": true,
34 | "fieldset": true,
35 | "figcaption": true,
36 | "figure": true,
37 | "footer": true,
38 | "form": true,
39 | "frame": true,
40 | "frameset": true,
41 | "h1": true,
42 | "h2": true,
43 | "h3": true,
44 | "h4": true,
45 | "h5": true,
46 | "h6": true,
47 | "head": true,
48 | "header": true,
49 | "hgroup": true,
50 | "hr": true,
51 | "html": true,
52 | "iframe": true,
53 | "img": true,
54 | "input": true,
55 | "isindex": true,
56 | "li": true,
57 | "link": true,
58 | "listing": true,
59 | "marquee": true,
60 | "menu": true,
61 | "meta": true,
62 | "nav": true,
63 | "noembed": true,
64 | "noframes": true,
65 | "noscript": true,
66 | "object": true,
67 | "ol": true,
68 | "p": true,
69 | "param": true,
70 | "plaintext": true,
71 | "pre": true,
72 | "script": true,
73 | "section": true,
74 | "select": true,
75 | "source": true,
76 | "style": true,
77 | "summary": true,
78 | "table": true,
79 | "tbody": true,
80 | "td": true,
81 | "template": true,
82 | "textarea": true,
83 | "tfoot": true,
84 | "th": true,
85 | "thead": true,
86 | "title": true,
87 | "tr": true,
88 | "track": true,
89 | "ul": true,
90 | "wbr": true,
91 | "xmp": true,
92 | }
93 |
94 | func isSpecialElement(element *Node) bool {
95 | switch element.Namespace {
96 | case "", "html":
97 | return isSpecialElementMap[element.Data]
98 | case "svg":
99 | return element.Data == "foreignObject"
100 | }
101 | return false
102 | }
103 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/text/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/text/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/text/unicode/norm/input.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm
6 |
7 | import "unicode/utf8"
8 |
9 | type input struct {
10 | str string
11 | bytes []byte
12 | }
13 |
14 | func inputBytes(str []byte) input {
15 | return input{bytes: str}
16 | }
17 |
18 | func inputString(str string) input {
19 | return input{str: str}
20 | }
21 |
22 | func (in *input) setBytes(str []byte) {
23 | in.str = ""
24 | in.bytes = str
25 | }
26 |
27 | func (in *input) setString(str string) {
28 | in.str = str
29 | in.bytes = nil
30 | }
31 |
32 | func (in *input) _byte(p int) byte {
33 | if in.bytes == nil {
34 | return in.str[p]
35 | }
36 | return in.bytes[p]
37 | }
38 |
39 | func (in *input) skipASCII(p, max int) int {
40 | if in.bytes == nil {
41 | for ; p < max && in.str[p] < utf8.RuneSelf; p++ {
42 | }
43 | } else {
44 | for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ {
45 | }
46 | }
47 | return p
48 | }
49 |
50 | func (in *input) skipContinuationBytes(p int) int {
51 | if in.bytes == nil {
52 | for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ {
53 | }
54 | } else {
55 | for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ {
56 | }
57 | }
58 | return p
59 | }
60 |
61 | func (in *input) appendSlice(buf []byte, b, e int) []byte {
62 | if in.bytes != nil {
63 | return append(buf, in.bytes[b:e]...)
64 | }
65 | for i := b; i < e; i++ {
66 | buf = append(buf, in.str[i])
67 | }
68 | return buf
69 | }
70 |
71 | func (in *input) copySlice(buf []byte, b, e int) int {
72 | if in.bytes == nil {
73 | return copy(buf, in.str[b:e])
74 | }
75 | return copy(buf, in.bytes[b:e])
76 | }
77 |
78 | func (in *input) charinfoNFC(p int) (uint16, int) {
79 | if in.bytes == nil {
80 | return nfcData.lookupString(in.str[p:])
81 | }
82 | return nfcData.lookup(in.bytes[p:])
83 | }
84 |
85 | func (in *input) charinfoNFKC(p int) (uint16, int) {
86 | if in.bytes == nil {
87 | return nfkcData.lookupString(in.str[p:])
88 | }
89 | return nfkcData.lookup(in.bytes[p:])
90 | }
91 |
92 | func (in *input) hangul(p int) (r rune) {
93 | if in.bytes == nil {
94 | if !isHangulString(in.str[p:]) {
95 | return 0
96 | }
97 | r, _ = utf8.DecodeRuneInString(in.str[p:])
98 | } else {
99 | if !isHangul(in.bytes[p:]) {
100 | return 0
101 | }
102 | r, _ = utf8.DecodeRune(in.bytes[p:])
103 | }
104 | return r
105 | }
106 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/text/unicode/norm/transform.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm
6 |
7 | import (
8 | "unicode/utf8"
9 |
10 | "golang.org/x/text/transform"
11 | )
12 |
13 | // Reset implements the Reset method of the transform.Transformer interface.
14 | func (Form) Reset() {}
15 |
16 | // Transform implements the Transform method of the transform.Transformer
17 | // interface. It may need to write segments of up to MaxSegmentSize at once.
18 | // Users should either catch ErrShortDst and allow dst to grow or have dst be at
19 | // least of size MaxTransformChunkSize to be guaranteed of progress.
20 | func (f Form) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
21 | n := 0
22 | // Cap the maximum number of src bytes to check.
23 | b := src
24 | eof := atEOF
25 | if ns := len(dst); ns < len(b) {
26 | err = transform.ErrShortDst
27 | eof = false
28 | b = b[:ns]
29 | }
30 | i, ok := formTable[f].quickSpan(inputBytes(b), n, len(b), eof)
31 | n += copy(dst[n:], b[n:i])
32 | if !ok {
33 | nDst, nSrc, err = f.transform(dst[n:], src[n:], atEOF)
34 | return nDst + n, nSrc + n, err
35 | }
36 | if n < len(src) && !atEOF {
37 | err = transform.ErrShortSrc
38 | }
39 | return n, n, err
40 | }
41 |
42 | func flushTransform(rb *reorderBuffer) bool {
43 | // Write out (must fully fit in dst, or else it is a ErrShortDst).
44 | if len(rb.out) < rb.nrune*utf8.UTFMax {
45 | return false
46 | }
47 | rb.out = rb.out[rb.flushCopy(rb.out):]
48 | return true
49 | }
50 |
51 | var errs = []error{nil, transform.ErrShortDst, transform.ErrShortSrc}
52 |
53 | // transform implements the transform.Transformer interface. It is only called
54 | // when quickSpan does not pass for a given string.
55 | func (f Form) transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
56 | // TODO: get rid of reorderBuffer. See CL 23460044.
57 | rb := reorderBuffer{}
58 | rb.init(f, src)
59 | for {
60 | // Load segment into reorder buffer.
61 | rb.setFlusher(dst[nDst:], flushTransform)
62 | end := decomposeSegment(&rb, nSrc, atEOF)
63 | if end < 0 {
64 | return nDst, nSrc, errs[-end]
65 | }
66 | nDst = len(dst) - len(rb.out)
67 | nSrc = end
68 |
69 | // Next quickSpan.
70 | end = rb.nsrc
71 | eof := atEOF
72 | if n := nSrc + len(dst) - nDst; n < end {
73 | err = transform.ErrShortDst
74 | end = n
75 | eof = false
76 | }
77 | end, ok := rb.f.quickSpan(rb.src, nSrc, end, eof)
78 | n := copy(dst[nDst:], rb.src.bytes[nSrc:end])
79 | nSrc += n
80 | nDst += n
81 | if ok {
82 | if n < rb.nsrc && !atEOF {
83 | err = transform.ErrShortSrc
84 | }
85 | return nDst, nSrc, err
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/text/unicode/norm/trie.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package norm
6 |
7 | type valueRange struct {
8 | value uint16 // header: value:stride
9 | lo, hi byte // header: lo:n
10 | }
11 |
12 | type sparseBlocks struct {
13 | values []valueRange
14 | offset []uint16
15 | }
16 |
17 | var nfcSparse = sparseBlocks{
18 | values: nfcSparseValues[:],
19 | offset: nfcSparseOffset[:],
20 | }
21 |
22 | var nfkcSparse = sparseBlocks{
23 | values: nfkcSparseValues[:],
24 | offset: nfkcSparseOffset[:],
25 | }
26 |
27 | var (
28 | nfcData = newNfcTrie(0)
29 | nfkcData = newNfkcTrie(0)
30 | )
31 |
32 | // lookupValue determines the type of block n and looks up the value for b.
33 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block
34 | // is a list of ranges with an accompanying value. Given a matching range r,
35 | // the value for b is by r.value + (b - r.lo) * stride.
36 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 {
37 | offset := t.offset[n]
38 | header := t.values[offset]
39 | lo := offset + 1
40 | hi := lo + uint16(header.lo)
41 | for lo < hi {
42 | m := lo + (hi-lo)/2
43 | r := t.values[m]
44 | if r.lo <= b && b <= r.hi {
45 | return r.value + uint16(b-r.lo)*header.value
46 | }
47 | if b < r.lo {
48 | hi = m
49 | } else {
50 | lo = m + 1
51 | }
52 | }
53 | return 0
54 | }
55 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/text/unicode/norm/triegen.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build ignore
6 |
7 | // Trie table generator.
8 | // Used by make*tables tools to generate a go file with trie data structures
9 | // for mapping UTF-8 to a 16-bit value. All but the last byte in a UTF-8 byte
10 | // sequence are used to lookup offsets in the index table to be used for the
11 | // next byte. The last byte is used to index into a table with 16-bit values.
12 |
13 | package main
14 |
15 | import (
16 | "fmt"
17 | "io"
18 | )
19 |
20 | const maxSparseEntries = 16
21 |
22 | type normCompacter struct {
23 | sparseBlocks [][]uint64
24 | sparseOffset []uint16
25 | sparseCount int
26 | name string
27 | }
28 |
29 | func mostFrequentStride(a []uint64) int {
30 | counts := make(map[int]int)
31 | var v int
32 | for _, x := range a {
33 | if stride := int(x) - v; v != 0 && stride >= 0 {
34 | counts[stride]++
35 | }
36 | v = int(x)
37 | }
38 | var maxs, maxc int
39 | for stride, cnt := range counts {
40 | if cnt > maxc || (cnt == maxc && stride < maxs) {
41 | maxs, maxc = stride, cnt
42 | }
43 | }
44 | return maxs
45 | }
46 |
47 | func countSparseEntries(a []uint64) int {
48 | stride := mostFrequentStride(a)
49 | var v, count int
50 | for _, tv := range a {
51 | if int(tv)-v != stride {
52 | if tv != 0 {
53 | count++
54 | }
55 | }
56 | v = int(tv)
57 | }
58 | return count
59 | }
60 |
61 | func (c *normCompacter) Size(v []uint64) (sz int, ok bool) {
62 | if n := countSparseEntries(v); n <= maxSparseEntries {
63 | return (n+1)*4 + 2, true
64 | }
65 | return 0, false
66 | }
67 |
68 | func (c *normCompacter) Store(v []uint64) uint32 {
69 | h := uint32(len(c.sparseOffset))
70 | c.sparseBlocks = append(c.sparseBlocks, v)
71 | c.sparseOffset = append(c.sparseOffset, uint16(c.sparseCount))
72 | c.sparseCount += countSparseEntries(v) + 1
73 | return h
74 | }
75 |
76 | func (c *normCompacter) Handler() string {
77 | return c.name + "Sparse.lookup"
78 | }
79 |
80 | func (c *normCompacter) Print(w io.Writer) (retErr error) {
81 | p := func(f string, x ...interface{}) {
82 | if _, err := fmt.Fprintf(w, f, x...); retErr == nil && err != nil {
83 | retErr = err
84 | }
85 | }
86 |
87 | ls := len(c.sparseBlocks)
88 | p("// %sSparseOffset: %d entries, %d bytes\n", c.name, ls, ls*2)
89 | p("var %sSparseOffset = %#v\n\n", c.name, c.sparseOffset)
90 |
91 | ns := c.sparseCount
92 | p("// %sSparseValues: %d entries, %d bytes\n", c.name, ns, ns*4)
93 | p("var %sSparseValues = [%d]valueRange {", c.name, ns)
94 | for i, b := range c.sparseBlocks {
95 | p("\n// Block %#x, offset %#x", i, c.sparseOffset[i])
96 | var v int
97 | stride := mostFrequentStride(b)
98 | n := countSparseEntries(b)
99 | p("\n{value:%#04x,lo:%#02x},", stride, uint8(n))
100 | for i, nv := range b {
101 | if int(nv)-v != stride {
102 | if v != 0 {
103 | p(",hi:%#02x},", 0x80+i-1)
104 | }
105 | if nv != 0 {
106 | p("\n{value:%#04x,lo:%#02x", nv, 0x80+i)
107 | }
108 | }
109 | v = int(nv)
110 | }
111 | if v != 0 {
112 | p(",hi:%#02x},", 0x80+len(b)-1)
113 | }
114 | }
115 | p("\n}\n\n")
116 | return
117 | }
118 |
--------------------------------------------------------------------------------