Categorygithub.com/eidng8/go-simple-tree
modulepackage
0.1.2
Repository: https://github.com/eidng8/go-simple-tree.git
Documentation: pkg.go.dev

# README

go-simple-tree

A simple hierarchical tree listing OpenAPI v3 microservice.

Every item has one parent at maximum, and can have multiple children. The service is generated using ent, entoas and oapi-codegen tools.

Usage

  1. Fork or download the package;
  2. go mod tidy in root and tools dir;
  3. Change constants in the following files to match your project (excerpts below):
  4. Comment out stuffs at the bottom of ent/schema/item.go following comments in the file;
  5. Run go generate to generate the ent client, ignore errors during generation;
  6. Bring back those lines commented in step 4;
  7. Run go generate again, there's should be no error this time;
  8. Manually diff and merge 3 files:
    • ent/openapi.go <=> /openapi.go
    • tools/services.gen.go <=> /services.gen.go
    • tools/types.gen.go <=> /types.gen.go
  9. Update any file to match the newly generate endpoint if necessary;
  10. Run go test to verify;
  11. Do anything with the new service.

Manually merging the files would be a better way to avoid messing up the existing code.

// ent/schema/item.go
package schema

import (
    // imports...
)

/* Change these 2 constants to match your project. */

// BaseUri is the base URI for the OpenAPI endpoints.
const BaseUri = "/your-endpoint-base-uri"

// TableName is the name of the table in the database.
const TableName = "your_database_table_name"

type Item struct {
    // ........
}
// tools/entc.go
package main

import (
    // imports...
)

/* Change these 2 constants to match your project. */

// BaseUri is the base URI for the OpenAPI endpoints.
const BaseUri = "/your-endpoint-base-uri"

// TableName is the name of the table in the database.
const TableName = "your_database_table_name"

func main() {
    // ........
}

// ...... snipped ......

func genSpec(s *ogen.Spec) {
    /* Change these information to match your project. */
    s.Info.SetTitle("Simple tree listing API").SetVersion("0.0.1").
        SetDescription("This is an API listing hierarchical tree data")
}

Environment Variables

The following environment variables are needed to stat the service.

BASE_URL

REQUIRED and cannot be empty. Determines the base URL for all URL generation. It should be the fully qualified URL without endpoint path.

LISTEN

REQUIRED and defaults to :80. Determines the gin server listening TCP network address. e.g. localhost:8080.

GIN_MODE

OPTIONAL and defaults to release. Can be one of debug, test, or release.

DB_DRIVER

REQUIRED and cannot be empty. Determines what kind of database to connect. Can be any driver supported by database/sql, such as mysql, sqlite3, pgx, etc. Remember to import proper driver module to your package.

DB_DSN

REQUIRED for connections other than MySQL. A complete DSN string to be used to establish connection to database. When set, this variable is passed directly to sql.Open(). For MySQL, if this variable is not set, variables below will be used to configure the connection.

Variables specific to MySQL

These variables are used to configure the connection to MySQL, if DB_DSN is not set.

DB_USER

REQUIRED and cannot be empty. Determines the username to connect to database.

DB_PASSWORD

REQUIRED and cannot be empty. Determines the password to connect to database.

DB_HOST

REQUIRED and cannot be empty. Determines the host to connect to.

DB_NAME

REQUIRED and cannot be empty. Determines the database name to connect to.

DB_PROTOCOL

OPTIONAL and defaults to tcp.

DB_COLLATION

OPTIONAL and defaults to utf8mb4_unicode_ci.

DB_TIMEZONE

OPTIONAL and defaults to UTC.

# Packages

No description provided by the author

# Functions

GetSwagger returns the Swagger specification corresponding to the generated code in this file.
No description provided by the author
Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
RegisterHandlers creates http.Handler with routing matching OpenAPI spec.
RegisterHandlersWithOptions creates http.Handler with additional options.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
CreateItemJSONBody defines parameters for CreateItem.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DeleteItemParams defines parameters for DeleteItem.
No description provided by the author
GinServerOptions provides options for the Gin server.
Item defines model for Item.
ItemCreate defines model for ItemCreate.
ItemList defines model for ItemList.
ItemParentRead defines model for Item_ParentRead.
ItemRead defines model for ItemRead.
ItemUpdate defines model for ItemUpdate.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ListItemChildrenParams defines parameters for ListItemChildren.
No description provided by the author
No description provided by the author
ListItemParams defines parameters for ListItem.
No description provided by the author
N400 defines model for 400.
No description provided by the author
N404 defines model for 404.
No description provided by the author
N409 defines model for 409.
No description provided by the author
N500 defines model for 500.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ReadItemParams defines parameters for ReadItem.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ServerInterfaceWrapper converts contexts to parameters.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
UpdateItemJSONBody defines parameters for UpdateItem.
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ServerInterface represents all server handlers.
StrictServerInterface represents all server handlers.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
CreateItemJSONRequestBody defines body for CreateItem for application/json ContentType.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
UpdateItemJSONRequestBody defines body for UpdateItem for application/json ContentType.