func newApp()

in docker_image/telemetry/main.go [49:106]


func newApp(client telemetryClient) *iris.Application {
	app := iris.New()
	app.Use(iris.Compression)
	endpoint := "/telemetry"
	sourceRegexs := filterSources()
	if len(sourceRegexs) == 0 {
		panic("AT LEAST SOURCE_REGEX_0 ENVIRONMENT VARIABLE IS REQUIRED")
	}
	app.Post(endpoint, func(c *context.Context) {
		var tags map[string]string
		err := c.ReadBody(&tags)
		if err != nil {
			c.StatusCode(iris.StatusBadRequest)
			_, _ = c.WriteString("incorrect tags")
			return
		}
		var source string
		var ok bool
		if source, ok = tags["module_source"]; !ok {
			c.StatusCode(iris.StatusBadRequest)
			_, _ = c.WriteString("module_source required")
			return
		}
		match := false
		for _, r := range sourceRegexs {
			if r.MatchString(source) {
				match = true
				break
			}
		}
		if !match {
			c.StatusCode(iris.StatusForbidden)
			_, _ = c.WriteString("source not allowed")
			return
		}
		var event, resourceId string
		if event, ok = tags["event"]; !ok {
			c.StatusCode(iris.StatusBadRequest)
			_, _ = c.WriteString("event required")
			return
		}
		if resourceId, ok = tags["resource_id"]; !ok {
			c.StatusCode(iris.StatusBadRequest)
			_, _ = c.WriteString("resource_id required")
		}
		telemetry := appinsights.NewEventTelemetry(event)
		telemetry.Properties = tags
		telemetry.Tags.User().SetAccountId(resourceId)
		client.Track(telemetry)
		c.StatusCode(iris.StatusOK)
	})
	// For health check
	app.Get(endpoint, func(c *context.Context) {
		c.StatusCode(iris.StatusOK)
		_, _ = c.WriteString("ok")
	})
	return app
}