35 lines
666 B
Go
35 lines
666 B
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/NothAmor/SourceTraceFront/common"
|
|
"github.com/NothAmor/SourceTraceFront/proto"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SubmitUrl(c *gin.Context) {
|
|
type submitUrlArgs struct {
|
|
Url string `json:"url"`
|
|
}
|
|
var args submitUrlArgs
|
|
if err := c.ShouldBindJSON(&args); err != nil {
|
|
log.Printf("failed to bind json: %v", err)
|
|
return
|
|
}
|
|
|
|
rpcArgs := proto.SubmitURLArgs{
|
|
URL: args.Url,
|
|
}
|
|
var reply proto.SubmitURLResp
|
|
err := common.RPC.Call(context.Background(), "Search", rpcArgs, &reply)
|
|
if err != nil {
|
|
log.Printf("failed to call: %v", err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, reply)
|
|
}
|