Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Jul 26, 2023
1 parent 7d63821 commit ecdfeb6
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions server/handler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package handler
import (
"encoding/json"
"net/http"
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/parser/terror"
Expand Down Expand Up @@ -52,12 +51,14 @@ const (

//revive:enable

// WriteError writes error to response.
func WriteError(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusBadRequest)
_, err = w.Write([]byte(err.Error()))
terror.Log(errors.Trace(err))
}

// WriteData writes data to response.
func WriteData(w http.ResponseWriter, data interface{}) {
js, err := json.MarshalIndent(data, "", " ")
if err != nil {
Expand All @@ -70,18 +71,3 @@ func WriteData(w http.ResponseWriter, data interface{}) {
_, err = w.Write(js)
terror.Log(errors.Trace(err))
}

// ExtractTableAndPartitionName extracts table name and partition name from a string.
func ExtractTableAndPartitionName(str string) (string, string) {
// extract table name and partition name from this "table(partition)":
// A sane person would not let the the table name or partition name contain '('.
start := strings.IndexByte(str, '(')
if start == -1 {
return str, ""
}
end := strings.IndexByte(str, ')')
if end == -1 {
return str, ""
}
return str[:start], str[start+1 : end]
}

0 comments on commit ecdfeb6

Please sign in to comment.