utils

package module
v0.0.0-...-0ee358a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2017 License: BSD-2-Clause Imports: 20 Imported by: 0

Documentation

Overview

Used for print everything as json.Marshal Created by simplejia 9/2016

Index

Examples

Constants

This section is empty.

Variables

View Source
var GRACEFUL_ENV = "GRACEFUL=true"
View Source
var LocalIp = func() string {
	ifaces, err := net.Interfaces()
	if err != nil {
		log.Println("utils.LocalIp error:", err)
		return ""
	}
	for _, iface := range ifaces {
		if iface.Flags&net.FlagUp == 0 {
			continue
		}
		if iface.Flags&net.FlagLoopback != 0 {
			continue
		}
		addrs, err := iface.Addrs()
		if err != nil {
			log.Println("utils.LocalIp error:", err)
			return ""
		}
		for _, addr := range addrs {
			var ip net.IP
			switch v := addr.(type) {
			case *net.IPNet:
				ip = v.IP
			case *net.IPAddr:
				ip = v.IP
			}
			if ip == nil || ip.IsLoopback() {
				continue
			}
			ip = ip.To4()
			if ip == nil {
				continue
			}
			if IsInnerIp(ip.String()) {
				return ip.String()
			}
		}
	}
	log.Println("utils.LocalIp failed!")
	return ""
}()

Functions

func Get

func Get(gpp *GPP) (body []byte, err error)

func Hash33

func Hash33(src string) int

func Iprint

func Iprint(a ...interface{}) string

func IprintD

func IprintD(a ...interface{})
Example
package main

import "time"

type P struct {
	I int
}

type C struct {
	P
	J string
	T time.Time
	M map[int]*P
}

func main() {
	var v interface{}
	IprintD(v)
	v = 1
	IprintD(v)
	v = "str"
	IprintD(v)
	v = &P{I: 1}
	IprintD(v)
	v = &C{P: P{I: 1}, J: "a", M: map[int]*P{1: &P{I: 2}}}
	IprintD(v)
	v = map[string]int{"a": 1}
	IprintD(v)
	v = map[int]int{1: 2}
	IprintD(v)
	v = map[interface{}]int{1: 2}
	IprintD(v)
	i := 1
	v = map[*int]int{&i: 2}
	IprintD(v)
	v = map[int]*C{1: &C{P: P{I: 1}, J: "a", M: map[int]*P{1: &P{I: 2}}}}
	IprintD(v)

}
Output:

null
1
"str"
{
  "I": 1
}
{
  "J": "a",
  "M": {
    "1": {
      "I": 2
    }
  },
  "P": {
    "I": 1
  },
  "T": "0001-01-01T00:00:00Z"
}
{
  "a": 1
}
{
  "1": 2
}
{
  "1": 2
}
{
  "1": 2
}
{
  "1": {
    "J": "a",
    "M": {
      "1": {
        "I": 2
      }
    },
    "P": {
      "I": 1
    },
    "T": "0001-01-01T00:00:00Z"
  }
}

func IsInnerIp

func IsInnerIp(src_ip string) bool

func ListenAndServe

func ListenAndServe(addr string, handler http.Handler) error

func Post

func Post(gpp *GPP) (body []byte, err error)

func RemoveAnnotation

func RemoveAnnotation(src []byte) []byte

func Slice2Interface

func Slice2Interface(slice interface{}) (ret []interface{})

Types

type GPP

type GPP struct {
	Uri     string
	Timeout time.Duration
	Headers map[string]string
	Params  interface{}
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr string, handler http.Handler, waitTime time.Duration) *Server

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL