This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic-setup for the development. able to do p2p connection and basic …
…debug.api
- Loading branch information
1 parent
2b27144
commit 165efad
Showing
2,627 changed files
with
900,977 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cc_go | ||
========== | ||
This is the frontend development template based on cookie-cutter. | ||
|
||
git clone https://github.com/chhsiao1981/cc_go.git cc; ./cc/scripts/init_dev.sh; . __/bin/activate | ||
|
||
* create module: ./scripts/dev_module.sh | ||
* create struct: ./scripts/dev_struct.sh | ||
|
||
Introduction | ||
----- | ||
This template intends to efficiently develop with the following libraries: | ||
|
||
* cookiecutter | ||
|
||
All are welcome to improve this template. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"pkg": "", | ||
"module": "", | ||
|
||
"project": "", | ||
|
||
"pkg_name": "", | ||
"project_name": "", | ||
|
||
"package_dir": "", | ||
|
||
"PKG": "", | ||
"MODULE": "", | ||
"PROJECT": "", | ||
"PKG_NAME": "", | ||
"PROJECT_NAME": "", | ||
"INCLUDE_PKG": "", | ||
"PACKAGE_DIR": "", | ||
"INCLUDE_PACKAGE_DIR": "", | ||
"TEST_PACKAGE_DIR": "", | ||
|
||
"Pkg": "", | ||
"Module": "", | ||
"Project": "", | ||
"PkgName": "", | ||
"ProjectName": "", | ||
"IncludePkg": "", | ||
"PackageDir": "", | ||
"IncludePackageDir": "", | ||
"TestPackageDir": "", | ||
|
||
"pkgLCamel": "", | ||
"moduleLCamel": "", | ||
"projectLCamel": "", | ||
"pkgName": "", | ||
"projectName": "", | ||
"includePkg": "", | ||
"packageDir": "", | ||
"includePackageDir": "", | ||
"testPackageDir": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../cookiecutter.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2018 The go-pttai Authors | ||
// This file is part of the go-pttai library. | ||
// | ||
// The go-pttai library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-pttai library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-pttai library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package {{cookiecutter.pkg_name}} | ||
|
||
var () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2018 The go-pttai Authors | ||
// This file is part of the go-pttai library. | ||
// | ||
// The go-pttai library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-pttai library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-pttai library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package {{cookiecutter.pkg_name}} | ||
|
||
const ( | ||
) | ||
|
||
var ( | ||
) | ||
|
||
func init() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright 2018 The go-pttai Authors | ||
// This file is part of the go-pttai library. | ||
// | ||
// The go-pttai library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-pttai library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-pttai library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
) | ||
|
||
const () | ||
|
||
var ( | ||
ctx context.Context = nil | ||
cancel context.CancelFunc = nil | ||
tBootnode *exec.Cmd = nil | ||
|
||
ctxs []context.Context = nil | ||
cancels []context.CancelFunc = nil | ||
nodes []*exec.Cmd = nil | ||
stderrs []io.ReadCloser = nil | ||
|
||
NNodes = 3 | ||
TimeoutSeconds = 120 * time.Second | ||
) | ||
|
||
type RBody struct { | ||
Body []byte | ||
} | ||
|
||
func GetResponseBody(r *RBody) func(res *http.Response, req *http.Request) error { | ||
return func(res *http.Response, req *http.Request) error { | ||
body, err := readBody(res) | ||
if err != nil { | ||
return err | ||
} | ||
r.Body = body | ||
return nil | ||
} | ||
} | ||
|
||
func readBody(res *http.Response) ([]byte, error) { | ||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
// Re-fill body reader stream after reading it | ||
res.Body = ioutil.NopCloser(bytes.NewBuffer(body)) | ||
return body, err | ||
} | ||
|
||
func setupTest(t *testing.T) { | ||
os.MkdirAll("./test.out", 0755) | ||
|
||
ctx, cancel = context.WithTimeout(context.Background(), TimeoutSeconds) | ||
|
||
tBootnode = exec.CommandContext(ctx, "../build/bin/bootnode", "--nodekeyhex", "03f509202abd40be562951247c7fe05294bb71ccad54f4853f2d75e3bf94affd", "--addr", "127.0.0.1:9488") | ||
err := tBootnode.Start() | ||
if err != nil { | ||
t.Errorf("unable to start tBootnode, e: %v", err) | ||
} | ||
|
||
ctxs = make([]context.Context, NNodes) | ||
cancels = make([]context.CancelFunc, NNodes) | ||
nodes = make([]*exec.Cmd, NNodes) | ||
stderrs = make([]io.ReadCloser, NNodes) | ||
|
||
for i := 0; i < NNodes; i++ { | ||
dir := fmt.Sprintf("./test.out/.test%d", i) | ||
rpcport := fmt.Sprintf("%d", 9450+i) | ||
port := fmt.Sprintf("%d", 9500+i) | ||
httpaddr := fmt.Sprintf("127.0.0.1:%d", 9600+i) | ||
|
||
ctxs[i], cancels[i] = context.WithTimeout(context.Background(), TimeoutSeconds) | ||
nodes[i] = exec.CommandContext(ctxs[i], "../build/bin/gptt", "--datadir", dir, "--rpcaddr", "127.0.0.1", "--rpcport", rpcport, "--port", port, "--httpaddr", httpaddr, "--bootnodes", "pnode://03f509202abd40be562951247c7fe05294bb71ccad54f4853f2d75e3bf94affd@127.0.0.1:9488", "--ipcdisable") | ||
stderrs[i], _ = nodes[i].StderrPipe() | ||
err := nodes[i].Start() | ||
if err != nil { | ||
t.Errorf("unable to start node: i: %v e: %v", i, err) | ||
} | ||
} | ||
|
||
t.Logf("wait 3 seconds for node starting") | ||
time.Sleep(3 * time.Second) | ||
} | ||
|
||
func teardownTest(t *testing.T) { | ||
cancel() | ||
for i := 0; i < NNodes; i++ { | ||
cancels[i]() | ||
|
||
/* | ||
err, _ := ioutil.ReadAll(stderrs[i]) | ||
t.Logf("after teardownTest: (%v/%v) e: %v", i, NNodes, string(err)) | ||
*/ | ||
} | ||
|
||
os.RemoveAll("./test.out") | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
.cc/e2e/{{cookiecutter.project}}/e2e/{{cookiecutter.module}}_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2018 The go-pttai Authors | ||
// This file is part of the go-pttai library. | ||
// | ||
// The go-pttai library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-pttai library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-pttai library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
baloo "gopkg.in/h2non/baloo.v3" | ||
) | ||
|
||
func Test{{cookiecutter.Module}}(t *testing.T) { | ||
setupTest(t) | ||
defer teardownTest(t) | ||
|
||
t0 := baloo.New("http://127.0.0.1:9450") | ||
|
||
rbody := &RBody{} | ||
bodyString := `{"id": "testID", "method": "ptt_getVersion", "params": []}` | ||
t0.Post("/"). | ||
BodyString(bodyString). | ||
SetHeader("Content-Type", "application/json"). | ||
Expect(t). | ||
AssertFunc(GetResponseBody(rbody)). | ||
Done() | ||
|
||
t.Logf("after t0: body: %v", string(rbody.Body)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
|
||
import json | ||
import sys | ||
import logging | ||
|
||
from cookiecutter.main import cookiecutter | ||
|
||
|
||
def underscore_to_uppercase(the_str): | ||
return the_str.upper() | ||
|
||
|
||
def underscore_to_camelcase(the_str): | ||
the_list = the_str.split('_') | ||
return ''.join([each_str.title() for each_str in the_list]) | ||
|
||
def underscore_to_lower_camelcase(the_str): | ||
the_list = the_str.split('_') | ||
return the_list[0] + ''.join([each_str.title() for each_str in the_list[1:]]) | ||
|
||
the_module = sys.argv[1] | ||
full_name = sys.argv[2] | ||
|
||
logging.warning('full_name: %s', full_name) | ||
|
||
full_name_list = full_name.split('.') | ||
if len(full_name_list) == 1: | ||
pkg = full_name_list[0] | ||
module = full_name_list[0] | ||
project = full_name_list[0] | ||
|
||
pkg_name = pkg | ||
project_name = project | ||
|
||
package_dir = '.' | ||
else: | ||
pkg = full_name_list[-2] | ||
module = full_name_list[-1] | ||
project = full_name_list[-1] | ||
|
||
pkg_name = 'main' if full_name_list[0] == 'cmd' else pkg | ||
project_name = project | ||
|
||
package_dir = '/'.join(full_name_list[:-1]) | ||
|
||
|
||
the_dict = { | ||
'pkg': pkg, | ||
'module': module, | ||
# 'project': project, | ||
|
||
'pkg_name': pkg_name, | ||
'project_name': project_name, | ||
|
||
'package_dir': package_dir, | ||
|
||
'PKG': underscore_to_uppercase(pkg), | ||
'MODULE': underscore_to_uppercase(module), | ||
'PROJECT': underscore_to_camelcase(project), | ||
'PKG_NAME': underscore_to_uppercase(pkg_name), | ||
'PROJECT_NAME': underscore_to_camelcase(project_name), | ||
'PACKAGE_DIR': underscore_to_uppercase(package_dir), | ||
|
||
'Pkg': underscore_to_camelcase(pkg), | ||
'Module': underscore_to_camelcase(module), | ||
'Project': underscore_to_camelcase(project), | ||
'PkgName': underscore_to_camelcase(pkg_name), | ||
'ProjectName': underscore_to_camelcase(project_name), | ||
'PackageDir': underscore_to_camelcase(package_dir), | ||
|
||
'pkgLCamel': underscore_to_lower_camelcase(pkg), | ||
'moduleLCamel': underscore_to_lower_camelcase(module), | ||
'projectLCamel': underscore_to_lower_camelcase(project), | ||
'pkgName': underscore_to_lower_camelcase(pkg_name), | ||
'projectName': underscore_to_lower_camelcase(project_name), | ||
'packageDir': underscore_to_lower_camelcase(package_dir), | ||
} | ||
|
||
cookiecutter( | ||
'.cc/' + the_module, | ||
extra_context=the_dict, | ||
no_input=True, | ||
overwrite_if_exists=True, | ||
skip_if_file_exists=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../cookiecutter.json |
19 changes: 19 additions & 0 deletions
19
.cc/module/{{cookiecutter.project}}/{{cookiecutter.package_dir}}/errors.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2018 The go-pttai Authors | ||
// This file is part of the go-pttai library. | ||
// | ||
// The go-pttai library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-pttai library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-pttai library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package {{cookiecutter.pkg_name}} | ||
|
||
var () |
Oops, something went wrong.