Ejemplo n.º 1
0
func main() {
	logger.Init(logger.Config{"server.log", true})
	client.ProxyCheckUrl = *checkProxyMSEndpoint + "/check/proxy"
	ps, err := db.New(*dbDir)
	if err != nil {
		logger.Errf("Creating proxy storage: %v", err)
		os.Exit(1)
	}

	s := checker.CheckerService{Ps: ps}
	s.Start()

	ms := microservice.Microservice{Addr: ":8000"}
	ms.RegEP(
		endpoint.Endpoint{
			Path:   "/proxylist/new",
			Method: "POST",
			EdpHandler: endpoint.Adapt(endpoint.EdpHandlerFunc(handleNewProxyList),
				mw.JsonConv(), mw.JsonHeaders(), db.ProxyStorageAdapter(ps)),
			ErrHandler: mw.DefaultJsonErrHandler{},
		},
	)
	ms.RegEP(
		endpoint.Endpoint{
			Path:   "/proxylist",
			Method: "GET",
			EdpHandler: endpoint.Adapt(endpoint.EdpHandlerFunc(handleProxyList),
				mw.JsonConv(), mw.JsonHeaders(), db.ProxyStorageAdapter(ps)),
			ErrHandler: mw.DefaultJsonErrHandler{},
		},
	)
	ms.Start()
}
Ejemplo n.º 2
0
func JsonHeaders() endpoint.Adapter {
	return func(e endpoint.EdpHandler) endpoint.EdpHandler {
		return endpoint.EdpHandlerFunc(func(c context.Context,
			r http.ResponseWriter, req *http.Request) (*endpoint.EPErr, context.Context) {
			r.Header()["Content-type"] = []string{"application/json"}
			return e.Handle(c, r, req)
		})
	}
}
Ejemplo n.º 3
0
func JsonConv() endpoint.Adapter {
	return func(e endpoint.EdpHandler) endpoint.EdpHandler {
		return endpoint.EdpHandlerFunc(func(c context.Context,
			r http.ResponseWriter, req *http.Request) (*endpoint.EPErr, context.Context) {
			nc := context.WithValue(c, jsonConvKey, &JsonConverter{in: req.Body, out: r})
			return e.Handle(nc, r, req)
		})
	}
}
Ejemplo n.º 4
0
Archivo: db.go Proyecto: pomkine/weasel
func ProxyStorageAdapter(storage *ProxyStorage) endpoint.Adapter {
	return func(e endpoint.EdpHandler) endpoint.EdpHandler {
		return endpoint.EdpHandlerFunc(func(c context.Context,
			r http.ResponseWriter, req *http.Request) (*endpoint.EPErr, context.Context) {
			nc := context.WithValue(c, proxyStorageKey, storage)
			return e.Handle(nc, r, req)
		})
	}
}
Ejemplo n.º 5
0
func main() {
	logger.Init(logger.Config{"server.log", true})
	ms := microservice.Microservice{Addr: ":6060"}
	ms.RegEP(
		endpoint.Endpoint{
			Path:   "/check/proxy",
			Method: "POST",
			EdpHandler: endpoint.Adapt(endpoint.EdpHandlerFunc(handleProxyCheck),
				mw.JsonConv(), mw.JsonHeaders()),
			ErrHandler: mw.DefaultJsonErrHandler{},
		},
	)
	ms.Start()
}