# Is there an equivalent of Go init function in Crystal or Kemal?

**URL:** <https://forum.crystal-lang.org/t/is-there-an-equivalent-of-go-init-function-in-crystal-or-kemal/762>\
**Category:** Offtopic\
**Created:** [May 11, 2019, 10:32pm UTC](https://forum.crystal-lang.org/t/is-there-an-equivalent-of-go-init-function-in-crystal-or-kemal/762 "2019-05-11T22:32:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)\
**Post date:** [May 11, 2019, 10:32pm UTC](https://forum.crystal-lang.org/t/is-there-an-equivalent-of-go-init-function-in-crystal-or-kemal/762/1 "2019-05-11T22:32:15Z")

</div>

Go language has this notion of `init` function, which is run once when the server starts. I put code for checking if database tables exist and if not to create them in this function. How can I achieve this in either Crystal or Kemal?

Thank you.

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [May 11, 2019, 10:55pm UTC](https://forum.crystal-lang.org/t/is-there-an-equivalent-of-go-init-function-in-crystal-or-kemal/762/2 "2019-05-11T22:55:21Z")

</div>

Any code in the top level of a required file contributes to the “main” code.

As long as the require is performed before the server starts listening for connections you should be good to go.

---

<div class="post-metadata">

**Author:** ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)\
**Post date:** [May 11, 2019, 11:13pm UTC](https://forum.crystal-lang.org/t/is-there-an-equivalent-of-go-init-function-in-crystal-or-kemal/762/3 "2019-05-11T23:13:54Z")

</div>

Great! Thanks. That works well.
