Capstan is a Golang web framework that shares some similarities with others in its segment.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.7KB

  1. package capstan
  2. // Upgrade functions are called whenever a new VFS is registered matching the
  3. // callee's pattern.
  4. type upgradeFunc func(VFS)
  5. // Downgrade functions are called whenever the VFS layer encounters an error or
  6. // panics. In this case, previous VFSes are returned until no more layers are
  7. // available and the panic is bubbled to the router.
  8. type downgradeFunc func(VFS)
  9. type VFS interface {
  10. }
  11. // VFSRegistry works by storing available virtual file systems and a series of
  12. // upgrade/downgrade listeners. As a new VFS is added as an upgrade, metadata
  13. // related to it is passed to all registered upgraders which may then elect to
  14. // utilize the new VFS (or not). If an error or panic occurs when attempting to
  15. // access a VFS, the downgrade callbacks are triggered for that VFS
  16. // automatically and the VFS reverts to its prior state.
  17. //
  18. // As an example, assume you have an application that is distributed with
  19. // migration scripts for a database embedded into the binary. The VFS, by
  20. // default, will utilize these migrations by default. However, also assume that
  21. // you provide migration upgrades that can occur out-of-band from the binary.
  22. // When you distribute these upgrades, your application can instruct the
  23. // VFSRegistry to upgrade the migrations listener, which will pass along another
  24. // VFS instance that reads from the updated .zip. This may be configured as a
  25. // passthrough VFS that will first attempt to read files from the .zip and then
  26. // fall back to those integrated into the binary.
  27. //
  28. // Another example: Assume you download a new theme that extends one of the core
  29. // templates distributed with your binary. You need access to both the new
  30. // theme's .zip and the integrated templates; you can have a VFS passthrough
  31. // that will read from both the .zip and the built-in theme separately, allowing
  32. // you to upgrade the new theme with add on .zips. If a new add on .zip doesn't
  33. // work to your liking, you could remove it, and when the VFS layer panics from
  34. // the missing file, it will downgrade itself until it either reverts to one of
  35. // the previous .zip files (my-theme-v2.zip to my-theme-v1.zip, for example) or
  36. // until it reverts to reading from the binary directly.
  37. //
  38. // Alternatively, you may also set up priorities such that files that exist in
  39. // the current working directory can override those contained in archives or
  40. // vice-versa.
  41. type VFSRegistry struct {
  42. Registry map[string][]VFS
  43. upgrades map[string][]upgradeFunc
  44. downgrades map[string][]downgradeFunc
  45. }
  46. func (r *VFSRegistry) OnUpgrade(fn upgradeFunc, passthrough bool) {
  47. }
  48. func (r *VFSRegistry) OnDowngrade(fn downgradeFunc, passthrough bool) {
  49. }
  50. type VFSPassThrough struct {
  51. }
  52. type VFSFilebox struct {
  53. }
  54. type VFSFileSystem struct {
  55. }
  56. type VFSZipFile struct {
  57. }