Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local variables #696

Open
johakoch opened this issue Feb 1, 2023 · 1 comment
Open

Local variables #696

johakoch opened this issue Feb 1, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@johakoch
Copy link
Collaborator

johakoch commented Feb 1, 2023

Provide a way to use locally defined variables

  • variables for less repetition and improved readability
  • local scope (within a block) (or perhaps global scope?)
  • name: vars/variables/declare

Example:

proxy {
  ...
  vars {
    expires_header = backend_responses.default.headers.expires
    http_date_format = "%a, %e %b %Y %T GMT"
  }
  add_response_headers = {
    # parse_date() is not (yet) a supported function
    Cache-Control = "max-age=${parse_date(http_date_format, expires_header) - unixtime()}" 
  }
}
# here: expires_header == null
@johakoch johakoch added the enhancement New feature or request label Feb 1, 2023
@johakoch
Copy link
Collaborator Author

johakoch commented Feb 1, 2023

Attributes in a block are defined by Couper's HCL flavour; in contrast to keys in an object type value (like add_response_headers), which are free to choose by the config writer.

So, if there should be a block, which can potentially appear anywhere in the config, the block must have an attribute with an object type value, like

proxy {
  declare {
    vars = {
      expires_header = backend_responses.default.headers.expires
      http_date_format = "%a, %e %b %Y %T GMT"
    }
  }
  ...
}

However, this may look quite verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant