Skip to main content
edited title; edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Parse long string in Go Simple HTTP server that performs a regex test

added 1 character in body
Source Link
dshil
  • 501
  • 2
  • 10
package controllers

import (
    "net/http"
    "strings""regexp"
)

type MessageController struct {
}

func NewMessageController() *MessageController {
    return &MessageController{}
}

func (mc *MessageController) ActionPost(res http.ResponseWriter, req *http.Request) {

    msgBody := req.URL.Query().Get("body")
    msgPattern := req.URL.Query().Get("pattern")

    isPatternFind := stringsregexp.ContainsMatchString(msgBodymsgPattern, msgPatternmsgBody)

    if isPatternFind {
        res.Write([]byte("find"))
    } else {
        res.Write([]byte("not find"))
    }
}
package controllers

import (
    "net/http"
    "strings"
)

type MessageController struct {
}

func NewMessageController() *MessageController {
    return &MessageController{}
}

func (mc *MessageController) ActionPost(res http.ResponseWriter, req *http.Request) {

    msgBody := req.URL.Query().Get("body")
    msgPattern := req.URL.Query().Get("pattern")

    isPatternFind := strings.Contains(msgBody, msgPattern)

    if isPatternFind {
        res.Write([]byte("find"))
    } else {
        res.Write([]byte("not find"))
    }
}
package controllers

import (
    "net/http"
    "regexp"
)

type MessageController struct {
}

func NewMessageController() *MessageController {
    return &MessageController{}
}

func (mc *MessageController) ActionPost(res http.ResponseWriter, req *http.Request) {

    msgBody := req.URL.Query().Get("body")
    msgPattern := req.URL.Query().Get("pattern")

    isPatternFind := regexp.MatchString(msgPattern, msgBody)

    if isPatternFind {
        res.Write([]byte("find"))
    } else {
        res.Write([]byte("not find"))
    }
}
edited tags
Link
dshil
  • 501
  • 2
  • 10

Another Parse long string in Go

Source Link
dshil
  • 501
  • 2
  • 10
Loading