mps

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

commit 481b4ad40fb7807d144f5133bc6c9149fc964d7e
parent 552c1bfc822457bb5949e9a0f384ccef07561b17
Author: MrGosti <gostitsog@gmail.com>
Date:   Tue,  2 May 2017 09:01:46 +0200

writing basic documentation for the main package and fixing all golint error

Diffstat:
Mdatabase.go | 6+++++-
Mmain.go | 6+++---
Mnetwork.go | 19++++++++++---------
3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/database.go b/database.go @@ -29,7 +29,7 @@ import ( _ "github.com/mattn/go-sqlite3" ) -// MPM package +//Package is a MPS internally used interface to make a bridge between the sql query and the resp_pkg type Package struct { ID uint64 Name string @@ -46,6 +46,7 @@ type Package struct { TimeAddPkg uint64 } +//RequestPackage return a `Package` struct corresponding to the packet passed as data func RequestPackage(data []byte, db *sql.DB) (int, Package, error) { pkg := Package{} @@ -72,6 +73,7 @@ func RequestPackage(data []byte, db *sql.DB) (int, Package, error) { return n, pkg, err } +//PkgtoRespPkg convert a `Package` to the correct reps_pkg packet func PkgtoRespPkg(pkg Package) (*response.RespPkg, error) { dep := strings.Split(pkg.Dependencies, ",") @@ -107,6 +109,7 @@ func PkgtoRespPkg(pkg Package) (*response.RespPkg, error) { return ret, nil } +//QueryPkgNameAndCat Query the database to get a package by its name or categories func QueryPkgNameAndCat(name string, category string, state uint8, db *sql.DB) (Package, error) { pkg := Package{} @@ -138,6 +141,7 @@ func QueryPkgNameAndCat(name string, category string, state uint8, db *sql.DB) ( return pkg, nil } +//QueryPkgID Query the database to get a package by its id func QueryPkgID(id uint64, state uint8, db *sql.DB) (Package, error) { pkg := Package{} rows, err := db.Query("SELECT * FROM pkgs where id = ?", id) diff --git a/main.go b/main.go @@ -29,8 +29,8 @@ import ( _ "github.com/mattn/go-sqlite3" ) -const MPM_MAJOR_VERSION uint8 = 0 -const MPM_MINOR_VERSION uint8 = 1 +// const MajorVersion uint8 = 0 +// const MinorVersion uint8 = 1 func main() { @@ -71,7 +71,7 @@ func main() { } if listener == nil { - fmt.Println("Error listening") + fmt.Println("Error listening: listener == nil (Maybe unbindable address)") os.Exit(1) } diff --git a/network.go b/network.go @@ -26,6 +26,7 @@ import ( "github.com/Morphux/mps/response" ) +//ParseRequest generate the correct interaction with the receive packet, return an error if any step fail func ParseRequest(data []byte, conn net.Conn, db *sql.DB) error { var cursor int var header = new(message.Header) @@ -44,7 +45,7 @@ func ParseRequest(data []byte, conn net.Conn, db *sql.DB) error { } //payload - cursor += 1 + cursor++ switch header.Type { case 0x01: @@ -64,24 +65,24 @@ func ParseRequest(data []byte, conn net.Conn, db *sql.DB) error { return err } - resp_data, err := resp.Pack() + respData, err := resp.Pack() if err != nil { return err } - fmt.Println(resp_data) + fmt.Println(respData) - resp_header := new(message.Header) + respHeader := new(message.Header) - resp_header.Build(0x20, 1, resp_data) + respHeader.Build(0x20, 1, respData) - header_data, err := resp_header.Pack() + headerData, err := respHeader.Pack() - fmt.Println("header", header_data, resp_header, message.BuildHeader(0x20, 1, resp_data)) + fmt.Println("header", headerData, respHeader, message.BuildHeader(0x20, 1, respData)) - tosend := append(message.BuildHeader(0x20, 1, resp_data), 0x1) - tosend = append(tosend, resp_data...) + tosend := append(message.BuildHeader(0x20, 1, respData), 0x1) + tosend = append(tosend, respData...) _, err = conn.Write(tosend)