Skip to content

sy-vendor/go-web

Repository files navigation

go-web

go-web based on GIN + Ent + Graph + WIRE (DI).

English | 中文

Features

  • Provides rich Gin middlewares (CORS)
  • Simplifies the interaction between the application and database with ENT, and automatically generates model code.
  • Supports multiple query languages, scalability, and multiple APIs with GRAPH.
  • Use Wire to resolve dependencies between modules
  • Uses Migrate for database version control

Dependent Tools

go get -u github.com/google/wire/cmd/wire
  • wire -- Compile-time Dependency Injection for Go

Dependent Library

  • Gin -- The fastest full-featured web framework for Go.
  • Wire -- Compile-time Dependency Injection for Go.
  • Graph -- A query language and runtime for APIs that simplifies data retrieval and manipulation.
  • Ent -- A framework for building scalable and maintainable software with Go.

Getting Started

$ git clone https://github.com/sy-vendor/go-web

$ cd go-web

$ go run cmd/apiserver/main.go

Use wire to generate dependency injection

wire ./cmd/apiserver

Create Database: user.go

ent init User

Modify module ./ent/schema/user.go

go generate ./ent

Rapidly generate business modules

Create a template under graph user.graphql

type User {
    id: ID!
    name: String!
    sex: Boolean!
    age: Int!
    Account: String!
    Password: String!
}

extend type Query {
    "find user by account"
    userByAccount(account: String!): User!
}

extend type Mutation {
    "update user account password"
    updatePasswordByAccount(account: String!, password: String!): User!
}

Execute command and run

go run github.com/99designs/gqlgen generate

go run ./cmd/apiserver/main.go

API request testing

https://studio.apollographql.com/
https://studio.apollographql.com/sandbox/explorer

About

gin + ent + graph + wire

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published