// handlerEvent is handler for POST:/event request.
handlerEvent is handler for POST:/event request.
// handlerEvent is handler for POST : / event request .
func handlerEvent(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	var err error
	start, code := time.Now(), http.StatusCreated
	defer func() {
		deferHandler(w, r, code, start, err)
	}()
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	if r.Method != "POST" {
		err = fmt.Errorf("%v method is not allowed", r.Method)
		return
	}
	defer r.Body.Close()
	decoder := json.NewDecoder(r.Body)
	req := &EventRequest{}
	err = decoder.Decode(req)
	if (err != nil) && (err != io.EOF) {
		loggerError.Printf("JSON decode eror: %v", err)
		return
	}
	result, err := Translate(ctx, req.Text)
	if err != nil {
		loggerError.Printf("translation eror: %v", err)
		return
	}
	if result == "" {
		err = errors.New("nothing")
		return
	}
	response := &EventResponse{
		Text: result,
		Bot:  Name,
	}
	w.WriteHeader(http.StatusCreated)
	encoder := json.NewEncoder(w)
	err = encoder.Encode(response)
	if err != nil {
		loggerError.Printf("failed json encode: %v", err)
	}
}
func handlerEvent ( ctx context . Context , w http . ResponseWriter , r * http . Request ) { var err error start , code := time . Now ( ) , http . StatusCreated defer func ( ) { deferHandler ( w , r , code , start , err ) } ( ) w . Header ( ) . Set ( " " , " " ) if r . Method != " " { err = fmt . Errorf ( " " , r . Method ) return } defer r . Body . Close ( ) decoder := json . NewDecoder ( r . Body ) req := & EventRequest { } err = decoder . Decode ( req ) if ( err != nil ) && ( err != io . EOF ) { loggerError . Printf ( " " , err ) return } result , err := Translate ( ctx , req . Text ) if err != nil { loggerError . Printf ( " " , err ) return } if result == " " { err = errors . New ( " " ) return } response := & EventResponse { Text : result , Bot : Name , } w . WriteHeader ( http . StatusCreated ) encoder := json . NewEncoder ( w ) err = encoder . Encode ( response ) if err != nil { loggerError . Printf ( " " , err ) } }
handlerEvent is handler for POST:/event request.
handlerEvent is handler for POST : / event request .