http.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2020 guylewin, guy@lewin.co.il
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package util
  15. import (
  16. "net/http"
  17. "strings"
  18. )
  19. func OkResponse() *http.Response {
  20. header := make(http.Header)
  21. res := &http.Response{
  22. Status: "OK",
  23. StatusCode: 200,
  24. Proto: "HTTP/1.1",
  25. ProtoMajor: 1,
  26. ProtoMinor: 1,
  27. Header: header,
  28. }
  29. return res
  30. }
  31. func GetHostFromAddr(addr string) (host string) {
  32. strs := strings.Split(addr, ":")
  33. if len(strs) > 1 {
  34. host = strs[0]
  35. } else {
  36. host = addr
  37. }
  38. return
  39. }