Documentation ¶
Overview ¶
Example ¶
Run "go test -c && ./ming800.test" to load config.json and do the test.
package main import ( "encoding/json" "fmt" "io/ioutil" "log" "path" "github.com/northbright/ming800" "github.com/northbright/pathhelper" ) // MyProcessor implements ming800.Processor interface to walk ming800. type MyProcessor struct { } func (p *MyProcessor) ClassHandler(class *ming800.Class) error { log.Printf("class: %v", class) return nil } func (p *MyProcessor) StudentHandler(class *ming800.Class, student *ming800.Student) error { log.Printf("class: %v, student: %v", class, student) return nil } // Run "go test -c && ./ming800.test" to load config.json and do the test. func main() { // 1. Create a "config.json" like this to load settings: /*{ "server_url": "http://localhost:8080", "company": "my_company", "user": "Frank", "password": "my_password" }*/ // 2. Run "go test -c && ./ming800.test" to load config.json and do the test. type Config struct { ServerURL string `json:"server_url"` Company string `json:"company"` User string `json:"user"` Password string `json:"password"` } var ( err error buf []byte currentDir, configFile string s *ming800.Session config Config ) defer func() { if err != nil { log.Printf("%v", err) } }() currentDir, _ = pathhelper.GetCurrentExecDir() configFile = path.Join(currentDir, "config.json") // Load Conifg if buf, err = ioutil.ReadFile(configFile); err != nil { err = fmt.Errorf("load config file error: %v", err) return } if err = json.Unmarshal(buf, &config); err != nil { err = fmt.Errorf("parse config err: %v", err) return } // New a session if s, err = ming800.NewSession(config.ServerURL, config.Company, config.User, config.Password); err != nil { err = fmt.Errorf("NewSession() error: %v", err) return } // Login if err = s.Login(); err != nil { err = fmt.Errorf("Login() error: %v", err) return } log.Printf("Login() successfully.\n") // Walk // Class and student handler will be called while walking ming800. processor := &MyProcessor{} if err = s.Walk(processor); err != nil { err = fmt.Errorf("Walk() error: %v", err) return } // Logout if err = s.Logout(); err != nil { err = fmt.Errorf("Logout() error: %v", err) return } log.Printf("logout() successfully.\n") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Class ¶
type Class struct { // Name is name of the class. Name string // Category is the category of the class. Category string // Teachers are the teachers of the class. One class can have multiple teachers. Teachers []string // ClassRoom is the class room of the class. ClassRoom string // Periods are the periods of the class. // One class may have 2 or more periods. Periods []string }
Class represents class information.
type Session ¶
type Session struct { // ServerURL is the server base URL of ming800. ServerURL string // Company is the company(orgnization) name for login. Company string // User is the user name of ming800. User string // Password is the user's password. Password string // LoggedIn represents login status. LoggedIn bool // contains filtered or unexported fields }
Session represents the login session and provides methods to interactive with ming800.
func NewSession ¶
NewSession creates a new session of ming800.
func (*Session) GetStudentDetails ¶
func (*Session) GetViewStudentURL ¶
GetViewStudentURL returns the URL of view student which response contains details of the student include customized column(e.g. ID card number).
func (*Session) Walk ¶
func (s *Session) Walk(processor WalkProcessor) error
Walk walks through the ming800.
type Student ¶
type Student struct { // ID is the internal ID of student. ID string // Name is the name of student. Name string // PhoneNum is the phone number of the contact for the student. PhoneNum string // Details store student information in key-value map. Details map[string]string }
Student represeents the student information.
type WalkProcessor ¶
type WalkProcessor interface { // ClassHandler is the callback when a class is found. ClassHandler(class *Class) error // StudentHandler is the callback when a student is found. StudentHandler(class *Class, student *Student) error }
WalkProcessor interface need users to implement callback functions while walking ming800.
Click to show internal directories.
Click to hide internal directories.