core

package module
v0.0.0-...-01f5b33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

README

p2pNG Core

开发环境

  • Requirements:
    • 安装Golang Version 1.15
    • 配置Go Modules环境变量
      • 方案1: 配置GOPROXY,例如使用https://goproxy.cn/
      • 方案2: 配置https_proxy,指向梯子的本地http代理端口
    • 建议使用GoLand IDE
    • 安装godoc,go get -u golang.org/x/tools/cmd/godoc
    • 安装golint,go get -u golang.org/x/lint/golint
  • Release Build:
  • Generate Docs

项目架构

- cmd       项目入口
    - commands  入口指令的定义
        - run //todo: 通过flags加载插件
- internal  内部使用的部分功能的包装
    - logging   日志记录的包装 //todo: 分流写入log文件
    - utils
- modules   提供Services使用的基础功能
    - certificate   用于测试的证书生成
    - database      用于本地储存的key-value DB
    - file_storage  本地文件的相关操作
    - listener      Http服务监听
    - request       Http请求发送   
- services  Http服务(以插件形式加载)
    - status        基础节点信息交互
    - discovery     用户发现:通过mDNS和DoH
    - transfer      Seed、FileBlock交换
    - manage        限制本地Loopback使用的Core实例管理
    - trust         证书的签发、用户认证:通过ACME和OCSP
    - ... 下面为下一版需求
    - legacy_http   提供传统Http服务
    - token         Token签发、交换、验证
    - traversal     兼容无公网的IPv4用户: 通过UPNP,STUN,Proxy

开发流程

  1. 首次开始代码工作的准备
    • 对于团队成员可直接将p2pNG/core 克隆到本地,git clone https://github.com/p2pNG/core
    • 对于非团队成员,需要先进行Fork 操作,并将其克隆到本地
  2. 每次开发前,从最新的远程master分支创建本地分支,
    git checkout master
    git pull
    git checkout -b [YOUR_BRANCH_NAME] master
    
  3. 对于团队成员,应注意如下几点
    • Commit Message中、Pull Request的标题中必须包含Jira中的任务编号,例如[P2PNG-27] Configure Github Actions CI
    • Branch命名也建议包含任务编号的数字部分,例如:27-configure-ci
    • 提交代码前,需要使用golint ./...确认代码不存在问题;使用go fmt ./...进行代码格式化
  4. [YOUR_BRANCH_NAME]branch上进行开发,完成开发后首次push如下 git push --set-upstream origin [YOUR_BRANCH_NAME]; 后续如有更多commit需要提交,直接git push到此分支即可
  5. 按照Console中提示,到GitHub中创建Pull Request,等待CI构建和检查、审阅、合并

Documentation

Index

Constants

View Source
const CoreImportPath = "github.com/p2pNG/core"

CoreImportPath is the package import path for p2pNG core.

Variables

This section is empty.

Functions

func GoModule

func GoModule() *debug.Module

GoModule returns the build info of this p2pNG build from debug.BuildInfo (requires Go modules). If no version information is available, a non-nil value will still be returned, but with an unknown version.

func RegisterRouterPlugin

func RegisterRouterPlugin(plugin RouterPlugin)

RegisterRouterPlugin is used to register a plugin Notice: should called by package init()

Types

type PluginInfo

type PluginInfo struct {
	Name    string
	Version string
	Prefix  string
	Buckets []string
}

PluginInfo is a type that describe a p2pNG plugin. Name is should be unique, usually use module path for it. Prefix indicates the http service path prefix. Buckets indicates which database bucket will use.

type RouterPlugin

type RouterPlugin interface {
	PluginInfo() *PluginInfo
	GetRouter() chi.Router
	Init() error
	Config() interface{}
}

RouterPlugin is a type that is used as a p2pNG plugin. p2pNG will call PluginInfo first, so PluginInfo should returns static info, then fill the Config and call Init, at last GetRouter() to mount and init database buckets.

func GetRouterPlugin

func GetRouterPlugin(name string) (p RouterPlugin, ok bool)

GetRouterPlugin return a RouterPlugin from registry that matches the key

func GetRouterPluginRegistry

func GetRouterPluginRegistry() []RouterPlugin

GetRouterPluginRegistry returns a list of all registered RouterPlugin

Directories

Path Synopsis
cmd
internal
modules
services

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL