コード例 #1
0
ファイル: main_test.go プロジェクト: netwars/api
func setupTestServer(client Client) *httptest.Server {
	topicCache := cache.NewCache(cache.CacheOpts{
		Expiration: 1000000 * time.Hour,
		Interval:   1000000 * time.Hour,
	})
	topicStorage := NewTopicStore(client, topicCache, TopicStoreOpts{
		WarmUp: warmUp,
	})
	go logErrorChannel("topic-storage", topicStorage.Err())

	ctx := context.Background()
	ctx = NewTopicStorageContext(ctx, topicStorage)

	return httptest.NewServer(buildRoutes(ctx))
}
コード例 #2
0
ファイル: main.go プロジェクト: netwars/api
func main() {
	// Flag domain. Note that gRPC transitively registers flags via its import
	// of glog. So, we define a new flag set, to keep those domains distinct.
	fs := flag.NewFlagSet("", flag.ExitOnError)

	fs.IntVar(&warmUp, "warmup", 0, "number of pages per forum to fetch on start")
	fs.StringVar(&debugAddr, "debug.addr", ":8000", "Address for HTTP debug/instrumentation server")
	fs.StringVar(&httpAddr, "http.addr", ":8001", "Address for HTTP (JSON) server")

	flag.Usage = fs.Usage // only show our flags
	if err := fs.Parse(os.Args[1:]); err != nil {
		log.Fatal(err)
	}

	logger := log.New(os.Stderr, "", log.LstdFlags)
	u, err := url.Parse(netwarsURL)
	if err != nil {
		logger.Fatal(err)
	}

	client := NewClient(u)
	topicCache := cache.NewCache(cache.CacheOpts{
		Expiration: storageEntryExpiration,
		Interval:   storageEntryInterval,
	})
	topicStorage := NewTopicStore(client, topicCache, TopicStoreOpts{
		WarmUp: warmUp,
	})
	go logErrorChannel("topic-storage", topicStorage.Err())

	// Transport: HTTP (debug/instrumentation)
	go func() {
		logger.Fatal(http.ListenAndServe(debugAddr, nil))
	}()

	ctx := context.Background()
	ctx = NewTopicStorageContext(ctx, topicStorage)

	logger.Fatal(http.ListenAndServe(httpAddr, buildRoutes(ctx)))
}