Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Go Programming - From Beginner to Professional - Second Edition

You're reading from  Go Programming - From Beginner to Professional - Second Edition

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781803243054
Pages 680 pages
Edition 2nd Edition
Languages
Author (1):
Samantha Coyle Samantha Coyle
Profile icon Samantha Coyle

Table of Contents (30) Chapters

Preface Part 1: Scripts
Chapter 1: Variables and Operators Chapter 2: Command and Control Chapter 3: Core Types Chapter 4: Complex Types Part 2: Components
Chapter 5: Functions – Reduce, Reuse, and Recycle Chapter 6: Don’t Panic! Handle Your Errors Chapter 7: Interfaces Chapter 8: Generic Algorithm Superpowers Part 3: Modules
Chapter 9: Using Go Modules to Define a Project Chapter 10: Packages Keep Projects Manageable Chapter 11: Bug-Busting Debugging Skills Chapter 12: About Time Part 4: Applications
Chapter 13: Programming from the Command Line Chapter 14: File and Systems Chapter 15: SQL and Databases Part 5: Building For The Web
Chapter 16: Web Servers Chapter 17: Using the Go HTTP Client Part 6: Professional
Chapter 18: Concurrent Work Chapter 19: Testing Chapter 20: Using Go Tools Chapter 21: Go in the Cloud Index Other Books You May Enjoy

Exercise 09.02 – using an external module within our module

Sometimes, in code, you need a unique identifier for an identity you provide to something. This unique identifier is often called a universally unique identifier (UUID). Google provides a package to create such a UUID. Let’s look at how to use it:

  1. Create a new directory called myuuidapp and navigate into it:
    mkdir myuuidapp
    cd myuuidapp
  2. Initialize a Go module named myuuidapp:
    go mod init myuuidapp
  3. Verify that the go.mod file is created within your project directory with the module path set as myuuidapp.
  4. Add a main.go file.
  5. In main.go, add the main package name to the top of the file:
    package main
  6. Now, add the imports we will use in this file:
    import (
        "fmt"
        "github.com/google/uuid"
    )
  7. Create the main() function:
    func main() {
  8. Generate a new UUID using the external module package:
        id := uuid.New...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}