Dash Golang Development and Deployment Guide

Author

Reads 1.3K

Crop unrecognizable developer using laptop and smartphone
Credit: pexels.com, Crop unrecognizable developer using laptop and smartphone

Dash is a popular framework for building web applications with the Go programming language. It provides a set of tools and libraries that make it easy to build and deploy web applications.

Dash allows you to build web applications with a single binary, eliminating the need for a separate web server process. This makes it ideal for building microservices and scalable web applications.

To get started with Dash, you'll need to install the Dash framework and its dependencies. You can do this using the Go package manager, Go get.

Dash provides a number of built-in features, including a built-in web server, a templating engine, and a routing system.

A different take: Golang Test Framework

Getting Started

To get started with Go, you'll need to install it correctly. Assuming you have Go installed, you can get the Cobra generator by running the command: $ cobra init.

Cobra will add some boilerplate code for you, which is handy because you can focus on the logic of your CLI instead of figuring out how to parse flags.

The generator creates an executable that you can run from anywhere, because it is located in the $GOPATH/bin directory, which is in turn added to your PATH variable if you installed Go correctly.

For more insights, see: Golang Go

Getting Started

A couple in aprons getting ready to renovate their home, showing teamwork and joy.
Credit: pexels.com, A couple in aprons getting ready to renovate their home, showing teamwork and joy.

To get started with goDASH, you'll need to install it. The easiest way is to use the install script available at the UCC Mobile and Internet System Lab MISL, or use the pre-defined configure file.

First, make sure you have Go installed correctly. You can check your GOPATH by using the command "go env $GOPATH". If you're using a collaborative environment, set "-serveraddr" to "on" in the goDASH config file.

Now, let's talk about Cobra. This framework provides a generator that adds boilerplate code for you, making it easier to focus on the logic of your CLI. Assuming you have Go installed, you can get the generator by running "cobra init" in your terminal.

The generator will create an executable in the $GOPATH/bin directory, which is added to your PATH variable if you installed Go correctly. This means you can run the executable from anywhere.

To start a new project, create a new folder for your Go code and navigate inside it with your terminal. Then, execute "cobra init" to generate a main.go file and a cmd package. By default, Cobra will add an Apache License, but you can opt out by adding the flag "-l none" to the generator commands.

You might enjoy: Go vs Golang

Choosing Technologies and Dependencies

Credit: youtube.com, Expect The Unexpected: How To Choose Reliable Open Source Dependencies by Theresa Mammarella &

Choosing the right technologies and dependencies can make all the difference in your project. The author of DevDash, for instance, is a big fan of the shell and uses it for everything.

The choice of technology should align with your strengths and goals. The author of DevDash is more of a backend person and didn't want to focus on building a UI, which simplified the process.

Golang is a great choice for building cross-platform binaries, making it easy to create binaries for Windows, MacOS, and Linux. This was a key factor in the author's decision to use Golang.

The author also values simplicity and ease of use. They love the simplicity of Golang, which is a very powerful language.

A self-contained binary and configuration file are all you need to get started with DevDash. This eliminates the need to install thousands of dependencies, unlike some other technologies like Node.js and npm.

Here are some key factors to consider when choosing technologies and dependencies:

  • Align your choice with your strengths and goals.
  • Simplify your process by choosing technologies that play to your strengths.
  • Consider the ease of use and simplicity of the technology.
  • Look for self-contained solutions that eliminate the need for complex installations.

Building and Deploying

Credit: youtube.com, How I Deploy my Go Backends!

To build the player, you'll need to update all repositories and dependencies.

You'll also need to install the P.1203 GitHub repository to output P.1203 QoE values.

Make sure to run P.1203 before using goDASH to accept their code.

Start Consul in a separate terminal using the command `consul agent -dev`.

Finally, call the single cooperative goDASH client using `./goDASH -config ../config/configure.json`.

Build Instructions

To build and deploy successfully, you'll need to update all repositories and dependencies. This will ensure you have the latest tools and resources to work with.

First, you'll need to run goDASH using the configure.json file. This is the best option for getting started.

Next, you'll need to install the P.1203 GitHub repository to output P.1203 QoE values. This is a crucial step, so don't skip it.

Once you've installed P.1203, make sure to run it before using goDASH. You'll need to accept their code, so be prepared to do so.

Now, start Consul in a separate terminal using the command 'consul agent -dev'. This will get Consul up and running.

Finally, call the single cooperative goDASH client using './goDASH -config ../config/configure.json'. This will launch the goDASH client with the correct configuration.

Expand your knowledge: Golang Run Debug Mode

Docker Containers

Credit: youtube.com, Building and deploying a Docker container to Kubernetes

Docker Containers offer a convenient way to deploy goDASH and goDASHbed.

We're releasing amd64 docker containers for both goDASH and goDASHbed with version 2.4.0+.

An arm64 version of goDASH is also available for users who need it.

A network build script is coming soon, allowing for a full evaluation of DASH algorithms within a Docker test framework.

You might like: Golang Version Manager

Push vs. Pull Metrics

When building and deploying your app, you'll need to decide how to get your metrics out of the app and into a service that can graph them. There are two main approaches: push and pull.

The push approach involves your app reporting metrics directly to a low-latency service, and then continuing with its work. This is what Google Analytics does, for example.

The pull approach, on the other hand, involves your app exposing metrics in a standard format at a predefined endpoint, which a collection service can then pull. The proc filesystem mounted at /proc and an SNMP agent that can be queried are examples of this approach.

Check this out: Door Dash Delivery App

Credit: youtube.com, How Prometheus Monitoring works | Prometheus Architecture explained

You'll need a service that can accept metrics or pull metrics, regardless of which approach you choose. Within Google, the pull approach is used, which is why the expvar package exists in the Go standard library.

If the pull approach suits you best, you might also want to take a look at Prometheus, which is a popular choice for this approach.

Here are the key differences between push and pull metrics:

Configuration and Management

Creating a dashboard in DevDash is as easy as writing YAML to choose the data displayed, the look of the widgets, and their sizes on the screen.

This flexibility is a key feature that sets DevDash apart from other terminal dashboards. You can configure your dashboard without needing to write any code.

To avoid polluting your command line or exposing sensitive data, consider using environment variables instead of flags. This is a good practice when working with sensitive information.

You can use Viper, a dependency from Steve Francia, to work with environment variables. Alternatively, you can use the os package from the Go standard library to achieve the same result.

Broaden your view: Golang Use Cases

Flexible and Simple Configuration

A smiling adult man using a desktop computer at a desk, creating a positive work environment.
Credit: pexels.com, A smiling adult man using a desktop computer at a desk, creating a positive work environment.

Creating a dashboard should be as easy as writing some yaml to choose the data displayed, the look of the widgets, their sizes on the screen.

The main feature that distinguishes DevDash from other terminal dashboards is its flexibility in configuration.

You can choose what data to display without needing to code anything, making it a user-friendly option.

This flexibility is achieved through a simple configuration process that allows users to customize their dashboard to their needs.

Using environment variables instead of flags is a good idea, especially when working with sensitive data that you don't want to show up in the command line history.

You can use Viper, another dependency from Steve Francia, to work with environment variables, which is already used by Cobra in the generated code.

Take a look at this: Golang Source

AddNewPeriod

In the context of configuration and management, AddNewPeriod is a crucial function that allows you to create a new Period and make it the currently active one.

Close-up image of a modern car dashboard featuring digital displays and speedometer.
Credit: pexels.com, Close-up image of a modern car dashboard featuring digital displays and speedometer.

This function is particularly useful for managing and organizing your tasks or projects in a structured manner.

By creating a new Period, you can effectively start fresh and focus on a specific set of tasks or goals without being bogged down by previous commitments.

The AddNewPeriod function is a simple yet powerful tool that can help you stay on top of your work and achieve your objectives.

Recommended read: Golang Func Type

AddNewRole

In configuration and management, adding a new role to an adaptation set is a crucial step. You can do this using the AddNewRole function, which is available for AdaptationSet objects.

The AddNewRole function takes two parameters: schemeIdUri and value. SchemeIdUri is a string that represents the scheme ID URI, specifically in the format urn:mpeg:dash:role:2011.

To add a new role, you'll need to provide a value for this role, such as caption, subtitle, main, alternate, supplementary, commentary, or dub. This value will be used to identify the role within the adaptation set.

Profile

Woman in focus working on software development remotely on laptop indoors.
Credit: pexels.com, Woman in focus working on software development remotely on laptop indoors.

When configuring and managing your system, understanding profiles is key.

Dash profiles are defined by constants, specifically for supported profiles.

There's a type definition for DASH profiles, which is crucial for configuration.

Constants for supported DASH profiles are essential for management.

You can find type definitions for DASH profiles in the relevant sections.

Adaptation Set and Representation

An Adaptation Set in DASH GoLang is essentially a container that holds multiple representations of a single media asset.

An Adaptation Set can hold various types of representations, such as Video, Audio, and Subtitle.

To add a new Video representation to an Adaptation Set, you need to specify the bandwidth, codecs, frame rate, width, and height. For example, a video representation might have a bandwidth of 1518664 bits per second, use the avc1.4d401f codec, have a frame rate of 30000/1001, and be 1280x720 pixels.

To create a new Adaptation Set for Audio Assets, you need to specify the MIME Type, segment alignment, whether it starts with SAP, and the language. For example, an Audio Adaptation Set might have a MIME Type of audio/mp4, segment alignment set to true, start with SAP, and be in the English language.

AddNewAdaptationSetAudio

Close-up of colorful programming code displayed on a computer screen.
Credit: pexels.com, Close-up of colorful programming code displayed on a computer screen.

Adding a new adaptation set for audio assets is a crucial step in creating a robust digital media delivery system. The MIME type, such as audio/mp4, needs to be specified to define the type of audio file.

You'll also need to decide on the segment alignment, which determines how the audio segments are aligned. In this case, the segment alignment is set to true.

Another important setting is the start with SAP, which is set to 1. This means that the audio asset will start with a synchronized audio playlist.

The language of the audio asset is also specified, in this case, it's set to English, or en.

See what others are reading: Golang Case Statement

Add Representation to Adaptation Set

To add a new representation to an Adaptation Set, you can use the AddNewRepresentationVideo method. This method adds a new Video representation to an AdaptationSet.

The bandwidth of the new video representation can be specified in Bits/s, such as 1518664. The codecs string for Audio Only can be used for video representations, and is typically in RFC6381 format.

Explore the sleek interior and advanced dashboard of the Ferrari 458 Speciale.
Credit: pexels.com, Explore the sleek interior and advanced dashboard of the Ferrari 458 Speciale.

The id parameter is used to identify the new representation, and will be used as $RepresentationID$ in template strings. The frameRate of the video can be specified as a fraction, such as 30000/1001.

The width and height of the video can also be specified, such as 1280 and 720 respectively. This is useful for specifying the resolution of the video.

You can also add a new Audio representation to an AdaptationSet using the AddNewRepresentationAudio method. The samplingRate of the new audio representation can be specified in Hz, such as 44100.

The bandwidth of the new audio representation can be specified in Bits/s, such as 67095. The codecs string for Audio Only can be used for audio representations, and is typically in RFC6381 format.

The id parameter is used to identify the new representation, and will be used as $RepresentationID$ in template strings.

Curious to learn more? Check out: Golang Template Html

AdaptationSet AddNewRepresentationSubtitle

Adding a new subtitle representation to an AdaptationSet is a straightforward process. You can use the AddNewRepresentationSubtitle method to achieve this.

Credit: youtube.com, Introduction: Adaptation and MPEG-DASH

The method requires two parameters: bandwidth and id. The bandwidth parameter specifies the bitrate in bits per second, which is a crucial aspect of video streaming.

For example, a bandwidth of 256 is a common value for subtitle representation. This value will be used to determine the quality of the subtitle stream.

The id parameter is a unique identifier for this representation, which will be used in template strings as $RepresentationID$. This identifier is essential for distinguishing between different subtitle representations within the AdaptationSet.

AdaptationSet SetNewSegmentTemplate

The AdaptationSet SetNewSegmentTemplate is a crucial function in setting up a new SegmentTemplate for an AdaptationSet. This template is used to determine the duration of media segments.

You can set the duration of a segment by specifying a relative value to the timescale, which is measured in milliseconds. For example, if the timescale is 1000, a duration of 2000 would result in a segment that is 2 seconds long.

Female Software Engineer Coding on Computer
Credit: pexels.com, Female Software Engineer Coding on Computer

The init template string is used to specify the filename for the init segment, which is a crucial part of the AdaptationSet. This string can include placeholders such as $RepresentationID$/audio/en/init.mp4, where $RepresentationID$ is a placeholder for the actual representation ID.

The media template string is used to specify the filename for media segments. This string can also include placeholders, such as $Number$, which is used to specify the segment number, starting from 0.

The startNumber parameter determines the segment number to start from, which is set to 0 by default. This means that the first media segment will be numbered 0.

Explore further: Golang String to Time

Dynamic Mpd and MPD

In the world of DASH (Dynamic Adaptive Streaming over HTTP), creating a dynamic MPD (Media Presentation Description) object is a crucial step. This object is created using the NewDynamicMPD function.

The NewDynamicMPD function requires a DASH Profile, which can be either Live or OnDemand. This profile determines the type of content being streamed.

Credit: youtube.com, NGINX streaming server part 8 (dash mpd)

The availabilityStartTime attribute serves as an anchor for calculating the earliest availability time in UTC. This is essential for ensuring that content is available at the right time.

Min Buffer Time is set to PT1.97S, which is the minimum buffer time required for smooth playback. This value can be adjusted based on the specific requirements of the streaming application.

Other attributes can be added using the attributes parameter, providing additional metadata for the dynamic MPD object.

Segment and Template

Dash is a high-level, full-featured Go web framework that makes it easy to build web applications. It provides a simple way to create web applications by organizing the code into smaller, reusable pieces called segments.

Segments are the building blocks of a Dash application and can be thought of as a single component or a group of components. They are created using the `html.Div` component from the `dash_html_components` package.

Dash also provides a way to create reusable UI components called templates. Templates can be used to define a set of UI components that can be used throughout an application.

Expand your knowledge: Golang Create Error

Credit: youtube.com, A Crash Course on Go Templates

Templates are created using the `html.Div` component and can contain other UI components such as buttons, text inputs, and more. They can be used to create consistent UI elements throughout an application.

Dash provides a number of built-in templates that can be used to create common UI elements such as navigation bars, dropdown menus, and more. These templates can be used to speed up development time and create a consistent look and feel throughout an application.

Dash also allows developers to create their own custom templates using the `html.Div` component. This allows for a high degree of flexibility and customization in the UI of an application.

Curious to learn more? Check out: Golang Create

Documentation and Development

Documentation is crucial for a project like DevDash, which offers a flexible way to configure a dashboard. It needs to be managed to handle the complexity.

A good documentation should have three main purposes: to quickly explain what the project is, propose an easy quickstart, and provide a detailed documentation for those who want personalized dashboards.

The current documentation is all in the README of the project, but this is overwhelming for users who just want to see what DevDash is. The documentation will be moved to a proper website in the future to make it more user-friendly.

Adding Functionality

Credit: youtube.com, Technical Writing: Functional Documentation

Adding functionality to your CLI is where the magic happens. It's the step where you get to decide what actions your CLI will perform.

A good practice is to work with verbs like get, post, describe, and for our example, we want the CLI to say hello. To do this, you can leverage the generator again to add a new command for you.

The generator will generate a file inside the cmd package called say.go. In this file, you can specify the way you want the command to be used and describe its function. The execute function gets executed every time you call hello-cli say.

You're probably never going to use it like that, except with a --help flag. If a user calls it like that, we want the user to know he needs to provide additional items to the say command. So, we're going to return an error if that happens.

Two professionals collaborating on software development in a modern indoor setting.
Credit: pexels.com, Two professionals collaborating on software development in a modern indoor setting.

The Run function of the cobra command doesn't return anything by default. You can however change Run to RunE, which expects the function to return an error if there is any. This is to show the user how to properly use your command.

At the bottom of the file, you'll see a function called init. Here you can add subcommands and flags. By default, the say command is added to the root command, which is exactly what we want.

Intriguing read: How to Run Golang File

Adding Flags

Adding flags can make your CLI more interesting by providing users with options to customize their experience. Local flags are available only for that command, whereas persistent flags are also available for the subcommands of that command.

To add a flag, you need to specify its full name, short notation, default value, and description. For example, to make a --name flag, you would add a string for the full name, a string for the short notation, a default value, and a description.

Here's an interesting read: Golang Add to Map

Credit: youtube.com, Feature Flags configuration, instrumentation and use

The full name of the flag can be executed with two dashes like --name. The short notation can be executed with one dash. The default value is used when no value is provided for the flag. A description is essential to help users understand the purpose of the flag.

To make the flag do something, you need to add some logic to the Run function. This is where the magic happens, and the flag starts to interact with the code. By adding the flag and its corresponding logic, you can provide users with a more engaging and customized experience.

An Effective Documentation

An effective documentation is crucial for any project, and DevDash is no exception. It should help users quickly understand what the project is about and whether it meets their needs.

DevDash's documentation has three main purposes: to quickly explain what DevDash is, propose an easy quickstart, and provide a detailed documentation of all configuration possibilities.

Credit: youtube.com, Writing effective documentation | Beth Aitman | #LeadDevBerlin

This is especially important because a flexible dashboard can introduce a lot of complexity, which needs to be managed. A strong documentation can help mitigate this complexity.

A good documentation should be easily accessible, and in DevDash's case, it's currently located in the README of the project. However, this can be overwhelming for users who just want to quickly assess the project.

To make it easier for users, most of the documentation will be moved to a proper website in the future.

Open Source Platform

For an open source project like DevDash, having a well-maintained platform is crucial. I've chosen Github as the platform for DevDash.

The description on Github should be concise and informative, summarizing the main ideas of the project. In DevDash's case, the description is "Highly Configurable Terminal Dashboard for Developers".

Tags are also essential for making the project easily discoverable on Github. DevDash has a bunch of tags for this purpose.

See what others are reading: Simple Http Server Golang Github

Credit: youtube.com, What I am working on? Golang dashboard cms

Visual elements can also make a project more appealing. In DevDash's README, you'll find a Gopher-logo, which is Golang's mascot.

Badges can show reassuring data, such as the state of the CI, code quality, and type of license. DevDash displays badges for these metrics.

Here's a summary of the key elements to include on your open source platform:

  • Concise and informative description
  • Relevant tags
  • Visual elements
  • Badges for reassuring data

Margarita Champlin

Writer

Margarita Champlin is a seasoned writer with a passion for crafting informative and engaging content. With a keen eye for detail and a knack for simplifying complex topics, she has established herself as a go-to expert in the field of technology. Her writing has been featured in various publications, covering a range of topics, including Azure Monitoring.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.