Coder Social home page Coder Social logo

go-web's Introduction

go-web

go好像完全没必要用框架

快速开始

// main.go
contact.Init()
defer contact.Close()

// contact.InitDB()
// defer contact.DbClose()

InitRoute().Run(fmt.Sprintf(":%d", contact.Config.App.Port))

//route.go
r := gin.Default()
r.Use(contact.GinCors())
r.GET("/", contact.GinHelpHandle(func(c *contact.GinHelp) {
	c.Resource("hello world!")
}))

配置

新建config.yml 数据结构: contact/config.go

curd

数据结构

CREATE TABLE `post`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `context` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

模型

// model/post.go
package model

import (
	"github.com/maxiloEmmmm/go-web/contact"
)

type Post struct {
	Id int
	Title string
	Context string
}

type PostModel struct {
	*contact.GORMM
}

func NewPostModel() *PostModel {
	return &PostModel{
		GORMM: &contact.GORMM{
			ResolveList: func() interface{} {
				tmp := make([]Post, 0)
				return &tmp
			},
			ResolveOne: func() interface{} {
				return new(Post)
			},
		},
	}
}

func (post PostModel)Fill(create bool) interface{} {
	return &Post{}
}

路由

// route.go
contact.CURD(r, "post", model.NewPostModel())

测试

http 配置文件

{
  "dev": {
    "ct": "application/json",
    "host": "http://localhost:8000/"
  }
}

http请求文件

### create
POST {{host}}/post
Content-Type: {{ct}}

{"payload": {"title": "3"}}

### list
GET {{host}}/post

### get
GET {{host}}/post/1

### update
PATCH {{host}}/post/1
Content-Type: {{ct}}

{"payload": {"title": "4"}}

### del
DELETE {{host}}/post/1
Content-Type: {{ct}}

go-web's People

Contributors

maxiloemmmm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.