# Getting started

> Add gosfc to an Astro or Vite project and write your first Go in a Vue component or an .astro file.

You need Go 1.27 or later and Node.js. The app is a Go module (a `go.mod` at
its root) as well as a Node.js project: the Go packages your components import
live in it.

## Install and set up Astro

1. Add goesm and gosfc to your Go module as tools. Their versions are pinned by go.mod / go.sum. gosfc needs goesm v0.0.1-beta.3 or later.

   ```sh
   go get -tool github.com/goesm-dev/goesm/cmd/goesm@<version>
   go get -tool github.com/goesm-dev/gosfc/cmd/gosfc@<version>
   ```

2. Install the integration from npm (`bun add @gosfc/astro`, `pnpm add @gosfc/astro` or `npm install @gosfc/astro`). For plain Vite + Vue projects, install `@gosfc/vite` instead.

3. Add the integration to Astro. When the project has `@astrojs/vue` installed, it is added if it is not already there. A project with Go only in `.astro` files needs neither Vue nor `@astrojs/vue`; [examples/astro-go](https://github.com/goesm-dev/gosfc/tree/v0.0.1-beta.7/examples/astro-go) is one.

   ```js
   // astro.config.mjs
   import { defineConfig } from "astro/config";
   import gosfc from "@gosfc/astro";

   export default defineConfig({
     integrations: [gosfc()],
   });
   ```

4. Use `<script setup lang="go">` in your `.vue` files.

   ```astro
   ---
   import Summary from "../features/cart/Summary.vue";
   ---

   <Summary />
   ```

   An `.astro` file can also be written in Go: see [Go in .astro files](https://goesm.dev/gosfc/guide/astro.md).

To use gosfc with Vite alone, put `@gosfc/vite` before `@vitejs/plugin-vue`.

```js
import vue from "@vitejs/plugin-vue";
import gosfc from "@gosfc/vite";

export default { plugins: [gosfc(), vue()] };
```

Components using `lang="ts"` or a plain `<script setup>` keep working alongside them. gosfc only touches components with `lang="go"`.

## Next steps

- [Writing the Go block](https://goesm.dev/gosfc/guide/go-block.md): what the block can contain and how
  the template sees it
- [Go in .astro files](https://goesm.dev/gosfc/guide/astro.md): Go in the frontmatter and `<script>` of
  `.astro` files
- [Importing Go from JavaScript](https://goesm.dev/gosfc/guide/importing-go.md): `go:` imports in `.astro`,
  `.ts` and `.js` files
