api

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// APIBasePath is the path to the API
	APIBasePath string

	// APIHost is the hostname
	APIHost string

	// APIProto for API access protocol
	APIProto string

	// HandlerChannel is used to communicate between the router and other application logic
	HandlerChannel chan HandlerMessage
)

Functions

func GenerateToken

func GenerateToken() string

GenerateToken creates a new token

func Logger

func Logger(inner http.Handler, name string) http.Handler

Logger handles the logging in the router

func NewRouter

func NewRouter(apiHost string, apiPath string, apiProto string, hmc chan HandlerMessage, ver string) *mux.Router

NewRouter creats a new instance of Router

func RobotHandler added in v1.2.4

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

RobotHandler process the request to /base

func UserHandler added in v1.2.4

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

UserHandler process the requests on the user

Types

type HandlerMessage

type HandlerMessage struct {
	Type  HandlerMessageType
	Value []interface{}
}

HandlerMessage contains the payload for the command messages

type HandlerMessageType

type HandlerMessageType int

HandlerMessageType is the type for HandlerMessage

const (
	// TypeAddUser is to add a user
	TypeAddUser HandlerMessageType = iota
	// TypeUserAdded says the user is added
	TypeUserAdded
	// TypeUserExisted says a user already exists
	TypeUserExisted
	// TypeInvalidUserInfo says something wrong about the user to be added
	TypeInvalidUserInfo
	// TypeDeleteUser is to delete a user
	TypeDeleteUser
	// TypeUserDeleted says the user is deleted
	TypeUserDeleted
	// TypeUserNotFound says no such user exists
	TypeUserNotFound
	// TypeGetUser is to get the current user
	TypeGetUser
	// TypeCurrentUser has the current user info
	TypeCurrentUser
	// TypeGetBase is to get Base
	TypeGetBase
	// TypeGetShoulder is to get Shoulder
	TypeGetShoulder
	// TypeGetElbow is to get Elbow
	TypeGetElbow
	// TypeGetWristAngle is to get WristAngle
	TypeGetWristAngle
	// TypeGetWristRotation is to get WristRotation
	TypeGetWristRotation
	// TypeGetGripper is to get Gripper
	TypeGetGripper
	// TypeGetPosture is to get a posture
	TypeGetPosture
	// TypeCurrentBase returns Base
	TypeCurrentBase
	// TypeCurrentShoulder returns Shoulder
	TypeCurrentShoulder
	// TypeCurrentElbow returns Elbow
	TypeCurrentElbow
	// TypeCurrentWristAngle returns WristAngle
	TypeCurrentWristAngle
	// TypeCurrentWristRotation returns WristRotation
	TypeCurrentWristRotation
	// TypeCurrentGripper returns Gripper
	TypeCurrentGripper
	// TypeCurrentPosture returns Posture
	TypeCurrentPosture
	// TypePutBase is to change Base
	TypePutBase
	// TypePutShoulder is to change Shoulder
	TypePutShoulder
	// TypePutElbow is to change Elbow
	TypePutElbow
	// TypePutWristAngle is to change WristAngle
	TypePutWristAngle
	// TypePutWristRotation is to change WristRotation
	TypePutWristRotation
	// TypePutGripper is to change Gripper
	TypePutGripper
	// TypePutPosture is to set a posture
	TypePutPosture
	// TypePutReset is to reset Leubot
	TypePutReset
	// TypePutSleep is to sleep Leubot
	TypePutSleep
	// TypeActionPerformed says the action was performed
	TypeActionPerformed
	// TypeInvalidToken says something is wrong with Token
	TypeInvalidToken
	// TypeInvalidCommand says no such command
	TypeInvalidCommand
	// TypeSomethingWentWrong says it didn't go well
	TypeSomethingWentWrong
)

func (HandlerMessageType) String added in v1.2.4

func (hmt HandlerMessageType) String() string

type JointInfo added in v1.2.2

type JointInfo struct {
	Name  string `json:"name"`
	Value uint16 `json:"value"`
}

JointInfo is a struct for each joint

type PostureCommand added in v1.1.1

type PostureCommand struct {
	Token         string `json:"token"`
	Base          uint16 `json:"base"`
	Shoulder      uint16 `json:"shoulder"`
	Elbow         uint16 `json:"elbow"`
	WristAngle    uint16 `json:"wristAngle"`
	WristRotation uint16 `json:"wristRotation"`
	Gripper       uint16 `json:"gripper"`
	Delta         uint8  `json:"delta"`
}

PostureCommand is a struct for a posture

type RobotCommand

type RobotCommand struct {
	Token string `json:"token"`
	Value uint16 `json:"value"`
}

RobotCommand is a struct for each command

type RobotPose added in v1.2.2

type RobotPose struct {
	Base          uint16
	Shoulder      uint16
	Elbow         uint16
	WristAngle    uint16
	WristRotation uint16
	Gripper       uint16
}

RobotPose stores the rotations of each joint

func (*RobotPose) BuildArmLinkPacket added in v1.2.2

func (rp *RobotPose) BuildArmLinkPacket(delta uint8) *armlink.ArmLinkPacket

BuildArmLinkPacket creates a new ArmLinkPacket

func (*RobotPose) String added in v1.2.2

func (rp *RobotPose) String() string

String returns a string rep for the rp

type Route

type Route struct {
	Name        string
	Methods     []string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route is a basic pattern of the rounting

type Routes

type Routes []Route

Routes contain the Route

type Token

type Token struct {
	Token string `json:"token"`
}

Token for the user token

type User

type User struct {
	Name  string
	Email string
	Token string
}

User provides the struct for the user

func NewUser

func NewUser(userInfo *UserInfo) *User

NewUser instantiate a user

func (*User) ToUserInfo

func (u *User) ToUserInfo() UserInfo

ToUserInfo parses User to UserInfo

type UserInfo

type UserInfo struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

UserInfo provides the JSON scheme for User

Jump to

Keyboard shortcuts

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