mps

morphux package server
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/mps

commit 0ae81d3e4989c4c0b6c240c8ff6cc958dca64a44
parent dcbc59ca238a1a692bc8fa45046145e523dac72d
Author: MrGosti <gostitsog@gmail.com>
Date:   Wed, 29 Mar 2017 09:10:47 +0200

Adding license and some documentation

Diffstat:
Mdatabase.go | 16++++++++++++++++
Mmessage/error.go | 25+++++++++++++++++++++----
Mmessage/header.go | 21++++++++++++++++++++-
Mmessage/message.go | 16++++++++++++++++
Mmessage/payload.go | 16++++++++++++++++
Mmps.go | 16++++++++++++++++
Mnetwork.go | 16++++++++++++++++
Mrequest/auth.go | 16++++++++++++++++
Mrequest/req_get_cat.go | 16++++++++++++++++
Mrequest/req_get_file.go | 16++++++++++++++++
Mrequest/req_get_news.go | 16++++++++++++++++
Mrequest/req_get_pkg.go | 16++++++++++++++++
Mrequest/req_get_upd.go | 16++++++++++++++++
Mresponse/authack.go | 16++++++++++++++++
Mresponse/resp_cat.go | 16++++++++++++++++
Mresponse/resp_file.go | 16++++++++++++++++
Mresponse/resp_news.go | 16++++++++++++++++
Mresponse/resp_pkg.go | 16++++++++++++++++
18 files changed, 297 insertions(+), 5 deletions(-)

diff --git a/database.go b/database.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package main import ( diff --git a/message/error.go b/message/error.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package message //An error happened server side @@ -17,6 +33,7 @@ type Error struct { Error string } +//PackError take a error and transform it to an mps.Error and pack it to []byte func (p *Error) PackError(err error, errortype uint8) ([]byte, error) { p.ErrorType = errortype p.Error = err.Error() @@ -25,25 +42,25 @@ func (p *Error) PackError(err error, errortype uint8) ([]byte, error) { return p.Pack() } -// Return Server Fault Message +//ServerFault Return Server Fault Message func ServerFault() []byte { errorMessage := []byte("An error happened server side") //len 0x1D return append([]byte{0x03, 0x25, 0x00, 0x00, 0x01, 0x01, 0x1D, 0x00}, errorMessage...) } -// Return Malformed Malformed Message +//MalformedPacket Return Malformed Malformed Message func MalformedPacket() []byte { errorMessage := []byte("A packet send by the client is wrong") //len 0x24 return append([]byte{0x03, 0x2C, 0x00, 0x00, 0x01, 0x02, 0x24, 0x00}, errorMessage...) } -// Return Ressource Not Found Message +//ResNotFound Return Ressource Not Found Message func ResNotFound() []byte { errorMessage := []byte("A request send by the client find no result") //len 0x2B return append([]byte{0x03, 0x33, 0x00, 0x00, 0x01, 0x03, 0x2B, 0x00}, errorMessage...) } -// Generate a Error Message +//GenerateError Generate a Error Message func GenerateError(Type uint8, message string) []byte { return append([]byte{Type, byte(len(message) + 8), 0x00, 0x00, 0x01, 0x03, byte(len(message)), 0x00}, []byte(message)...) } diff --git a/message/header.go b/message/header.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package message import "github.com/Morphux/mps/vendors/Nyarum/barrel" @@ -11,6 +27,7 @@ type Header struct { NextPkg string } +//Unpack []byte to a proper header object, return the number of byte used and an error func (h *Header) Unpack(data []byte) (int, error) { barrel := barrel.NewBarrel() @@ -26,6 +43,7 @@ func (h *Header) Unpack(data []byte) (int, error) { return 3 + int(h.NextPkgLen), nil } +//Build help to build a correct header func (h *Header) Build(Type, number uint8, data []byte) { h.Type = Type h.NextPkgLen = 0 @@ -35,6 +53,7 @@ func (h *Header) Build(Type, number uint8, data []byte) { } +//Pack an header to []byte func (p *Header) Pack() ([]byte, error) { barrel := barrel.NewBarrel() load := barrel.Load(p, []byte{}, true) @@ -48,7 +67,7 @@ func (p *Header) Pack() ([]byte, error) { func BuildHeader(Type, number uint8, data []byte) []byte { hash := "" - length := len(data) + 4 + 1; + length := len(data) + 4 + 1 header := []byte{Type, byte(length & 0xff), byte(length >> 8), byte(len(hash))} diff --git a/message/message.go b/message/message.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package message import "github.com/Morphux/mps/vendors/Nyarum/barrel" diff --git a/message/payload.go b/message/payload.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package message import "github.com/Morphux/mps/vendors/Nyarum/barrel" diff --git a/mps.go b/mps.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package main import ( diff --git a/network.go b/network.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package main import ( diff --git a/request/auth.go b/request/auth.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package request import "github.com/Morphux/mps/message" diff --git a/request/req_get_cat.go b/request/req_get_cat.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package request import "github.com/Morphux/mps/message" diff --git a/request/req_get_file.go b/request/req_get_file.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package request import "github.com/Morphux/mps/message" diff --git a/request/req_get_news.go b/request/req_get_news.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package request import "github.com/Morphux/mps/message" diff --git a/request/req_get_pkg.go b/request/req_get_pkg.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package request import ( diff --git a/request/req_get_upd.go b/request/req_get_upd.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package request import "github.com/Morphux/mps/message" diff --git a/response/authack.go b/response/authack.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package response import "github.com/Morphux/mps/message" diff --git a/response/resp_cat.go b/response/resp_cat.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package response import "github.com/Morphux/mps/message" diff --git a/response/resp_file.go b/response/resp_file.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package response import "github.com/Morphux/mps/message" diff --git a/response/resp_news.go b/response/resp_news.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package response import "github.com/Morphux/mps/message" diff --git a/response/resp_pkg.go b/response/resp_pkg.go @@ -1,3 +1,19 @@ +/*********************************** LICENSE **********************************\ +* Copyright 2017 Morphux * +* * +* Licensed under the Apache License, Version 2.0 (the "License"); * +* you may not use this file except in compliance with the License. * +* You may obtain a copy of the License at * +* * +* http://www.apache.org/licenses/LICENSE-2.0 * +* * +* Unless required by applicable law or agreed to in writing, software * +* distributed under the License is distributed on an "AS IS" BASIS, * +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +* See the License for the specific language governing permissions and * +* limitations under the License. * +\******************************************************************************/ + package response import (