/
serve.go
35 lines (31 loc) · 1.08 KB
/
serve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cmd
import "github.com/spf13/cobra"
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Initiate rest API interface",
Long: "Run a http server for managing notes/notebooks via REST calls\n" +
"If no -p flag is not set the default port will be 8080\n" +
"Available endpoints:\n" +
"POST /addNote \n" +
"PUT /updateNote \n" +
"GET /getNotesByID/{ids} (comma separated IDs) \n" +
"GET /getNotesByNotebookTitle/{notebookTitles} (comma separated notebook titles) \n" +
"GET /getNotesByTags/{Tags} (comma separated tags) \n" +
"GET /getAllNotes \n" +
"DELETE /deleteNotes/{ids} (comma separated IDs)\n" +
"GET /searchBy/{keyword} \n" +
"PUT /updateNotebook/{oldTitle}/{newTitle} \n" +
"DELETE /deleteNotebooks/{notebookTitles} (comma separated notebook titles)\n",
Example: "serve -p 7000",
Run: serve,
}
func serve(cmd *cobra.Command, args []string) {
port, _ := cmd.Flags().GetString("port")
server := NewServer()
server.Initialize()
server.Run(port)
}
func init() {
rootCmd.AddCommand(serveCmd)
serveCmd.Flags().StringP("port", "p", "8080", "Server port")
}