> Web

Router & CORS

1. Basic Setting We are developing a web applications. Gin is for backend and vue is for frontend. However, I often encouter router problems when sending request from frontend to the backend. Here are quick rules to avoid these problems. 2. Router //routers.go func Router() *gin.Engine { r := gin.Default() r.Use(middleware.Cors()) user := r.Group("/user") { user.GET("/test/", controllers.Test) user.GET("/", controllers.GetUsers) user.GET("/:id", controllers.GetUser) user.POST("/new", controllers.NewUser) user.POST("/update/:id", controllers.UpdateUser) } return r } <script> // add end slash const res = await $fetch("http://localhost:8080/user/test/") const res = await $fetch("http://localhost:8080/user/"); // no end slash const res = await $fetch("http://localhost:8080/user/1"); const res = await $fetch("http://localhost:8080/user/new", { .

Continue reading

Internet Basics

1. Open System Interconncetion Reference Model (OSI model) Physical Layer: Network interface controller (网卡), ethernet hub (集线器), network switch, transmission medium. It converts digital bits to electrical, radio or optical signals. Voltage characteristics are defined. Datalink Layer: Medium access control (MAC) layer, logical link control (LLC) layer. Correct errors that may occur in physical layers. Network Layer: Provides to transfer packets from node to node. (IP) Transport Layer: Provides to transfer variable length data sequences from source host to destination host.

Continue reading

Intro to Redis

1. Basic Concepts Redis is a NoSql database. Its characteristics are non-structured, non-relational, no SQL grammar. Other NoSQL includes MongoDB, elaticsearch. Besides, Redis only has base transaction. Redis stores key-value, runs in single thread with low latency. Data persistence is supported in case of blackout. 2. Install See Redis. For mac os, we can just run brew install redis 3. Basic Commands brew services start redis # start redis redis-cli -h 127.

Continue reading

All kinds of Django View

1. First Example Suppose that we are going to build a blog application. The following codes will create the index page. # urls.py urlpatterns = [ path('', views.index, name='index'), ] # views.py def index(request): latest = Post.objects.order_by("-modified_time") return render(request, "index.html", {"post_list": latest}) If we use View class, the codes will be easier to read. # urls.py urlpatterns = [ path('', views.IndexView.as_view(), name='index'), ] # views.py from django.views.generic import ListView class IndexView(ListView): queryset = Post.

Continue reading

bootstrap

1. Quick Start <head> ... <!-- development --> <link rel="stylesheet" href="static/plugins/bootstrap-3.4.1/css/bootstrap.css"> <!-- production --> <link rel="stylesheet" href="static/plugins/bootstrap-3.4.1/css/bootstrap.min.css"> <style> .navbar{ border-radius: 0; } </style> </head> <body> <!-- button --> <input type="button" value="enter" class="btn btn-primary"/> <!-- col-xs --> <div class="col-xs-offset-2 col-xs-2" style="color:red;">1</div> <div class="col-xs-2" style="color:green;">2</div> <!-- col-sm col-md col-lg --> </body>

Continue reading

Author's picture

LI WEI

苟日新,日日新,又日新

Not yet

Tokyo