Example #1
0
func Run() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	s := &http.Server{
		Addr:           core.GetConfig().Listen,
		Handler:        new(Handler),
		ReadTimeout:    10 * time.Second,
		MaxHeaderBytes: 8192,
	}
	log.Fatal(s.ListenAndServe())
}
Example #2
0
func Run(context *core.Context, res http.ResponseWriter, next core.Middleware) {
	if context.Req.Method != "PURGE" {
		next(context, res)
		return
	}

	ip := context.Req.RemoteAddr[0:strings.LastIndex(context.Req.RemoteAddr, ":")]
	if core.GetConfig().PurgeWhiteList[ip] == false {
		res.WriteHeader(401)
		return
	}

	if err := os.RemoveAll(context.Dir); err != nil {
		res.Write([]byte(err.Error()))
		res.WriteHeader(500)
	} else {
		res.WriteHeader(200)
	}
}
Example #3
0
func Run(context *core.Context) (*http.Response, error) {
	request := newRequest(context, core.GetConfig())
	return transport.RoundTrip(request)
}
Example #4
0
package logs

import (
	"github.com/garyburd/redigo/redis"
	"log"
	"net/http"
	"seedcdn/core"
	"time"
)

var pool = &redis.Pool{
	MaxIdle:     5,
	IdleTimeout: time.Minute * 5,
	Dial: func() (redis.Conn, error) {
		config := core.GetConfig()
		conn, err := redis.Dial(config.RedisProtocol, config.Redis)
		if err != nil {
			return nil, err
		}
		if _, err = conn.Do("select", config.RedisDB); err != nil {
			return nil, err
		}
		return conn, nil
	},
}

func Run(context *core.Context, res http.ResponseWriter, next core.Middleware) {
	go run(context)
	next(context, res)
}