Beispiel #1
0
package middleware

import (
	"time"

	"github.com/lgtmco/lgtm/cache"

	"github.com/gin-gonic/gin"
	"github.com/ianschenck/envflag"
)

var (
	ttl = envflag.Duration("CACHE_TTL", time.Minute*15, "")
)

func Cache() gin.HandlerFunc {
	cache_ := cache.NewTTL(*ttl)
	return func(c *gin.Context) {
		c.Set("cache", cache_)
		c.Next()
	}
}
Beispiel #2
0
func main() {
	var (
		hostport     = envflag.String("SHEEPDOG_HOSTPORT", "", "host:port pair for sheepdog cluster")
		readHostPort = envflag.String("SHEEPDOG_READ_HOSTPORT", "", "host:port pair for only issuing reads to sheepdog cluster")
		readDelay    = envflag.Duration("SHEEPDOG_READ_SLEEP", 0, "time to sleep between each read of test")
		payloadCount = envflag.Int("SHEEPDOG_TEST_PAYLOAD_COUNT", 10, "payload count to issue reads and writes to sheepdog")
		vdiSize      = envflag.Int("SHEEPDOG_VDI_SIZE", 1<<22, "create vdi of given size")
		vdiName      = envflag.String("SHEEPDOG_VDI_NAME", "testvdi", "name of vdi to test read/writes across")
	)
	envflag.Parse()

	c, err := picard.NewCluster(*hostport)
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("Created connection to sheepdog successfully")

	defer func() {
		if err := c.Disconnect(); err != nil {
			log.Fatalln(err)
		}
		log.Printf("Successfully disconnected!")
	}()

	vdi, err := c.CreateOpenVDI(*vdiName, uint64(*vdiSize))
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("Created and opened VDI successfully")

	defer func() {
		vdi.Close()
		if err := c.DeleteVDI(vdi.Name()); err != nil {
			log.Fatalln(err)
		}
		log.Printf("Successfully deleted vdi: %q", vdi.Name())
	}()

	rvdi := vdi
	if *readHostPort != "" {
		rc, err := picard.NewCluster(*readHostPort)
		if err != nil {
			log.Fatalln(err)
		}
		log.Printf("Created read connection to sheepdog successfully")

		defer func() {
			if err := rc.Disconnect(); err != nil {
				log.Fatalln(err)
			}
			log.Printf("Successfully disconnected for read connection!")
		}()

		rvdi, err = rc.OpenVDI(*vdiName)
		if err != nil {
			log.Fatalln(err)
		}
		log.Printf("Opened VDI successfully for reads")

		defer rvdi.Close()
	}

	vdiChan := make(chan *vdiData)

	go func() {
		if count, err := writeToVDI(vdi, vdiChan, *payloadCount); err != nil {
			log.Printf("Error while writing at %d: %s", count, err)
		}
	}()

	if count, failed, err := readFromVDI(rvdi, vdiChan, *readDelay); err != nil {
		log.Printf("Error occurred during reads:\n\tTotal: %d, Failures: %d\n\tError: %q", count, failed, err)
	}
}