go:embed and the golang-standards project layout

go:embed and the golang-standards project layout

While experimenting with Go and trying out the go:embed directive to serve a VueJS application I was running into an issue with trying to stick to the golang-standards project layout

This is because go:embed doesn't let you embed from parent directories and since in this specific scenario I was trying to have multiple services split into cmd/ subfolders this seemed to be at odds with each other.

Patterns may not contain ‘.’ or ‘..’ or empty path elements, nor may they begin or end with a slash.

source

This led me to a deep search into some other projects that may have ran into a similar problem and I found this commit on github https://github.com/lawrencejones/pgsink/commit/3b7c58f79e21b6b6dfffcdd8e7403bb1523747cb

Realising that by having a go package made of the web folder, I could reference it, so combining with using build tags to either serve by the os package when developing or serve by embed when building I had a solution that worked well.

Considering that I found many more questions asking how to do it when I searched, I figured I would provide an example.

Run

Run with using the embed.FS

go run -tags prod cmd/http/main.go

Run with the os.Dir

go run cmd/http/main.go

Browse to http://127.0.0.1:8080 to see the index.html

Similar Resources

A set of example golang code to start learning Go

Working with Go View online at: https://mkaz.blog/working-with-go/ Working with Go is a set of examples for Go (golang) to help an experienced program

Dec 23, 2022

Partially golang implement of openstack keystone client.

Keystone client Introduction The openapi folder is generated from keystone.yaml(i.e. the OAS) using openapi-generator-cli. Another OAS token.json is n

Jan 6, 2022

Get an embed.FS from inside an embed.FS

Get an embed.FS from inside an embed.FS

embed.FS wrapper providing additional functionality Features Get an embed.FS from an embedded subdirectory Handy Copy(sourcePath, targetPath) method t

Sep 27, 2022

Hexa is the open-source, standards-based policy orchestration software for multi-cloud and hybrid businesses.

Hexa Policy Orchestrator Hexa is the open-source, standards-based policy orchestration software for multi-cloud and hybrid businesses. The Hexa projec

Dec 22, 2022

Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.

Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.

Sensible and fast command-line flag parsing with excellent support for subcommands and positional values. Flags can be at any position. Flaggy has no

Jan 1, 2023

A practical Golang project layout

Golayout Golayout is a boilerplate project that containing the usage of the best practice and popular components. The code organization follows the st

Jul 12, 2022

An implementation of JOSE standards (JWE, JWS, JWT) in Go

Go JOSE Package jose aims to provide an implementation of the Javascript Object Signing and Encryption set of standards. This includes support for JSO

Dec 18, 2022

An implementation of JOSE standards (JWE, JWS, JWT) in Go

Go JOSE Package jose aims to provide an implementation of the Javascript Object Signing and Encryption set of standards. This includes support for JSO

Jan 8, 2023

Kubernetes Pod Security Standards implementation

Pod Security Admission The Pod Security Standards are a set of best-practice profiles for running pods securely. This repository contains the codified

Dec 30, 2022

Go Project Sample Layout

go-sample A sample layout for Go application projects with the real code. Where it all comes from? Ideas used to create the architecture and structure

Dec 26, 2022

Go Todo Backend example using modular project layout for product microservice.

go-todo-backend Go Todo Backend Example Using Modular Project Layout for Product Microservice. It's suitable as starting point for a medium to larger

Dec 29, 2022

Standard Go Project Layout

Standard Go Project Layout Translations: 한국어 문서 简体中文 正體中文 简体中文 - ??? Français 日本語 Español Overview This is a basic layout for Go application projects.

Jan 5, 2023

Generate scaffold project layout for Go.

scaffold Scaffold generates starter Go project layout. Let you can focus on buesiness logic implemeted. The following is Go project layout scaffold ge

Dec 11, 2022

Standard Go Project Layout

Standard Go Project Layout Translations: 한국어 문서 简体中文 正體中文 简体中文 - ??? Français 日本語 Portuguese Español Overview This is a basic layout for Go applicatio

Jan 2, 2023

Standard Go Project Layout

Standard Go Project Layout

This is a basic layout for Go application projects. It's not an official standard defined by the core Go dev team; however, it is a set of common historical and emerging project layout patterns in the Go ecosystem. Some of these patterns are more popular than others. It also has a number of small enhancements along with several supporting directories common to any large enough real world application.

Jan 3, 2023

Go structure annotations that supports encoding and decoding; similar to C-style bitfields. Supports bitfield packing, self-describing layout parameters, and alignment.

Go structure annotations that supports encoding and decoding; similar to C-style bitfields. Supports bitfield packing, self-describing layout parameters, and alignment.

STRUCTure EXtensions structex provides annotation rules that extend Go structures for implementation of encoding and decoding of byte backed data fram

Oct 13, 2022

Little golang app that allows you to download a youtube video as mp3, and optionally embed ID3 tags -Cover Art, Artist ...-

yt2mp3 Little golang app that allows you to download a youtube video as mp3, and optionally embed ID3 tags -Cover Art, Artist ...- Instructions At the

Dec 25, 2021

🔑A high performance Key/Value store written in Go with a predictable read/write performance and high throughput. Uses a Bitcask on-disk layout (LSM+WAL) similar to Riak.

bitcask A high performance Key/Value store written in Go with a predictable read/write performance and high throughput. Uses a Bitcask on-disk layout

Sep 26, 2022

Grab is a tool that downloads source code repositories into a convenient directory layout created from the repo's URL's domain and path

Grab is a tool that downloads source code repositories into a convenient directory layout created from the repo's URL's domain and path. It supports Git, Mercurial (hg), Subversion, and Bazaar repositories.

Jun 2, 2022
Go Todo Backend example using modular project layout for product microservice.

go-todo-backend Go Todo Backend Example Using Modular Project Layout for Product Microservice. It's suitable as starting point for a medium to larger

Dec 29, 2022
Standard Go Project Layout

Standard Go Project Layout Translations: 한국어 문서 简体中文 正體中文 简体中文 - ??? Français 日本語 Español Overview This is a basic layout for Go application projects.

Jan 5, 2023
Generate scaffold project layout for Go.

scaffold Scaffold generates starter Go project layout. Let you can focus on buesiness logic implemeted. The following is Go project layout scaffold ge

Dec 11, 2022
A go project generator, which aims to simplify building and releasing go projects by storing all project configuration in a single file called gojen.json, and creates appropriate workflow/git files using that config.

gojen Define your go project's configuration using a json config. This config can be used to generate a new go project for you, and can also create co

Mar 8, 2022
Golang Cafe - Go job board with no recruiters and clear salary ranges

Golang Cafe Golang Cafe is the first Go job board with no recruiters & clear salary ranges. Clear salary range in each job description No third party

Jan 6, 2023
Nwg-drawer is a golang replacement to the nwggrid command (a part of nwg-launchers).
Nwg-drawer is a golang replacement to the nwggrid command (a part of nwg-launchers).

Nwg-drawer is a golang replacement to the nwggrid command (a part of nwg-launchers). It's being developed with sway in mind, but should also work with other wlroots-based Wayland compositors. X Window System is not supported.

Dec 23, 2022
Epitech BSQ in Golang
Epitech BSQ in Golang

EPITECH BSQ in Golang BSQ GO What is BSQ ? The goal of the project is to find the biggest square on a map while avoiding obstacles. The file map is pa

Mar 7, 2022
Simple scaffolding for board or turn based games in Golang

Go-boardgame Go-boardgame is a simple Go package that can be used as the scaffolding to write the game logic for any board or turn based game. Status

May 26, 2022
This repository contains my Golang practice

Golang Practice Repository This repository contains my practice code for Golang. Each exercise includes a README for running the application. NOTE: TH

Nov 28, 2021
Golang Demo - simple API to get top ranking repos from online csv file

README Generator Description A Demo Golang project, topics : Simple Http Server Get csv from endpoint Convert csv to struct sort slice of struct filte

Dec 3, 2021