code: func metadataRequestHandler(rules *RuleSet) router.Handler {
  	return func(ctx *router.Context) {
  		c, w := ctx.Context, ctx.Writer
  
  		patterns, err := rules.ConfigPatterns(c)
  		if err != nil {
  			internalErrStatus(c, w, "Metadata: failed to collect the list of validation patterns", err)
  			return
  		}
  
  		meta := config.ServiceDynamicMetadata{
  			Version: metaDataFormatVersion,
  			Validation: &config.Validator{
  				Url: fmt.Sprintf("https://%s%s", ctx.Request.URL.Host, validationPath),
  			},
  		}
  		for _, p := range patterns {
  			meta.Validation.Patterns = append(meta.Validation.Patterns, &config.ConfigPattern{
  				ConfigSet: p.ConfigSet.String(),
  				Path:      p.Path.String(),
  			})
  		}
  
  		w.Header().Set("Content-Type", "application/json")
  		if err := json.NewEncoder(w).Encode(&meta); err != nil {
  			internalErrStatus(c, w, "Metadata: failed to JSON encode output", err)
  		}
  	}
  }
docs: // metadataRequestHandler handles the metadata request from luci-config and
  // responds with the necessary metadata defined by the given Validator.