Testing feeder.go using /api/index

Here's the feeder.go script to check if /api/index accepts index terms:

package main 
 
import ( 
    "bytes" 
    "encoding/json" 
    "io/ioutil" 
    "log" 
    "net/http" 
) 
 
type tPayload struct { 
    Token  string 'json:"token"' 
    Title  string 'json:"title"' 
    DocID  string 'json:"doc_id"' 
    LIndex int    'json:"line_index"' 
    Index  int    'json:"token_index"' 
} 
 
type msgS struct { 
    Code int    'json:"code"' 
    Msg  string 'json:"msg"' 
} 
 
func main() { 
    // Searching for "apple" should return Book 1 at the top of search results. 
    // Searching for "cake" should return Book 3 at the top. 
    for bookX, terms := range map[string][]string{ 
        "Book 1": []string{"apple", "apple", "cat", "zebra"}, 
        "Book 2": []string{"banana", "cake", "zebra"}, 
        "Book 3": []string{"apple", "cake", "cake", "whale"}, 
    } { 
        for lin, term := range terms { 
            payload, _ := json.Marshal(tPayload{ 
                Token:  term, 
                Title:  bookX + term, 
                DocID:  bookX, 
                LIndex: lin, 
            }) 
            resp, err := http.Post( 
                "http://localhost:9090/api/index", 
                "application/json", 
                bytes.NewBuffer(payload), 
            ) 
            if err != nil { 
                panic(err) 
            } 
            body, _ := ioutil.ReadAll(resp.Body) 
            defer resp.Body.Close() 
 
            var msg msgS 
            json.Unmarshal(body, &msg) 
            log.Println(msg) 
        } 
    } 
} 

The output from running feeder.go (with Librarian running in other window) is as follows:

$ go run feeder.go   
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}                            
2018/01/04 12:53:31 {200 Tokens are being added to index.}      

The output from Librarian for the preceding program is as follows:

$ go run goophr/librarian/main.go                               
2018/01/04 12:53:25 INFO -  Adding API handlers...                                    
2018/01/04 12:53:25 INFO -  Starting index...                                         
2018/01/04 12:53:25 INFO -  Starting Goophr Librarian server on port :9090...         
2018/01/04 12:53:31 Token received api.tPayload{Token:"banana", Title:"Book 2banana", DocID:"Book 2", LIndex:0, Index:0}                                                     
2018/01/04 12:53:31 Token received api.tPayload{Token:"cake", Title:"Book 2cake", DocID:"Book 2", LIndex:1, Index:0}                                                         
2018/01/04 12:53:31 Token received api.tPayload{Token:"zebra", Title:"Book 2zebra", DocID:"Book 2", LIndex:2, Index:0}                                                       
2018/01/04 12:53:31 Token received api.tPayload{Token:"apple", Title:"Book 3apple", DocID:"Book 3", LIndex:0, Index:0}                                                       
2018/01/04 12:53:31 Token received api.tPayload{Token:"cake", Title:"Book 3cake", DocID:"Book 3", LIndex:1, Index:0}                                                         
2018/01/04 12:53:31 Token received api.tPayload{Token:"cake", Title:"Book 3cake", DocID:"Book 3", LIndex:2, Index:0}                                                         
2018/01/04 12:53:31 Token received api.tPayload{Token:"whale", Title:"Book 3whale", DocID:"Book 3", LIndex:3, Index:0}                                                       
2018/01/04 12:53:31 Token received api.tPayload{Token:"apple", Title:"Book 1apple", DocID:"Book 1", LIndex:0, Index:0}                                                       
2018/01/04 12:53:31 Token received api.tPayload{Token:"apple", Title:"Book 1apple", DocID:"Book 1", LIndex:1, Index:0}                                                       
2018/01/04 12:53:31 Token received api.tPayload{Token:"cat", Title:"Book 1cat", DocID:"Book 1", LIndex:2, Index:0}                                                           
2018/01/04 12:53:31 Token received api.tPayload{Token:"zebra", Title:"Book 1zebra", DocID:"Book 1", LIndex:3, Index:0}     
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.76.72