core

package
v0.0.0-...-66eb22f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2017 License: MIT Imports: 15 Imported by: 4

README

judger包(core目录)

judger包是一个简易(tiny)的Service-Router-Controller框架

网络通讯

传输协议TCP

客户端

"string\03"

每次发送一个字符串,字符串的结尾以ASCII码0x03结束,由于0x03是不可见字符,故串的正文部分不应该包含0x03不可见字符。

字符串的正文格式为json格式如下

密码验证
{
	"action":	"login",			//action name
	"ip":		"127.0.0.1",		//client ip
	"password": "password",			//password string
	"time":		123456789			//timestamp
}
提交任务
{
	"action":	"task_add",			//action name
	"id":		12,					//task id, task id must be unique
	"time":		123456789,			//timestamp
	"language":	"C",				//language
	"code":		"here is code"		//code,code应该是经过html转义的
}
查询任务状态
{
	"action":	"task_status",		//action name
	"id":		12,					//task id
	"time":		123456789
}
服务端

服务端返回数据也是json格式

密码验证

登录成功

{
	"result":	true,				//bool, login result
	"os":		"linux x86",
	"language":	{					//language:compiler
					"C":	"gcc",
					"C++":	"g++",
					"Java":	"javac version 1.7"
				},
	"time":		123456789			//server time stamp
}

登录失败

{
	"result":	false				//bool, login result
}
任务提交响应

提交成功

{
	"result":	true,
	"message":	"task in queue",
	"time":		123456789
}

提交失败

{
	"result":	false,
	"message":	"task commit failed, the reason is blablabla...",
	"time":		123456789
}
任务状态查询

查询失败(通常指任务不存在)

{
	"result":	false,
	"message":	"task is not exist",
	"time":		123456789
}

队列中

{
	"result":	true,
	"status":	"waitting",			//只存在waitting,success,failed三种类型
	"message":	"task in queue",
	"time":		123456789
}

通过

{
	"result":	true,
	"status":	"success",
	"log":		"here is compiler log and run log or any other logs",
	"time":		123456789
}

失败

{
	"result":	true,
	"status":	"failed",
	"log":		"here is compiler log and run log or any other logs",
	"time":		123456789
}
系统状态不可用
{
	"result":	false,
	"message":	"system failure",
	"time":		123456789
}
注意

注意,在发送数据的时候数据中不能够包含注释,否则会抛出异常,此问题不准备解决,为了节省流量发送的数据中不应该包含注释。

Documentation

Index

Constants

View Source
const (
	BUFF_SIZE = 10
	MAX_LCI   = 100
)

Variables

View Source
var MARK string
View Source
var Mode string

Functions

func GenScript

func GenScript()

func HandleJsonRpc

func HandleJsonRpc(w http.ResponseWriter, r *http.Request)

func HttpStart

func HttpStart()

func Judger

func Judger()

func Parse

func Parse(frame string, cli *Client)

func Router

func Router(actionName string, c ControllerInterface)

func TcpStart

func TcpStart()

Types

type Client

type Client struct {
	Conn net.Conn
	// contains filtered or unexported fields
}

func (*Client) Close

func (this *Client) Close()

/ close client connect from server

func (*Client) Login

func (this *Client) Login(value bool)

set mark for login value: true for login, false for not login

func (*Client) Write

func (this *Client) Write(str string)

send message to client and print in server console

type Config

type Config struct {
	// contains filtered or unexported fields
}
var C *Config

func (*Config) Get

func (this *Config) Get(key1 string, key2 string) string

get value via key arg1: key level 1 arg2: key level 2

func (*Config) NewConfig

func (this *Config) NewConfig(path string)

load config

type ControllerInterface

type ControllerInterface interface {
	Tcp(data map[string]interface{}, cli *Client)
	Http(data map[string]interface{}, w http.ResponseWriter, r *http.Request)
}

type Sqlite

type Sqlite struct {
	Filename string
}
var DB *Sqlite

func (*Sqlite) NewSqlite

func (this *Sqlite) NewSqlite(dataPath string)

Jump to

Keyboard shortcuts

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