{ "error":"Key: 'AddUserRequest.Username' Error:Field validation for 'Username' failed on the 'required' tag\nKey: 'AddUserRequest.Email' Error:Field validation for 'Email' failed on the 'required' tag" }
var bookableDate validator.Func = func(fl validator.FieldLevel)bool { date, ok := fl.Field().Interface().(time.Time) if ok { today := time.Now() if today.After(date) { returnfalse } } returntrue }
funcmain() { route := gin.Default()
if v, ok := binding.Validator.Engine().(*validator.Validate); ok { v.RegisterValidation("bookabledate", bookableDate) } ... }
type Person struct { Name string`form:"name"` Address string`form:"address"` }
funcstartPage(c *gin.Context) { var person Person if c.ShouldBindQuery(&person) == nil { log.Println(person.Name) log.Println(person.Address) } c.String(200, "Success") }
type Person struct { Name string`json:"name"` Address string`json:"address"` }
funcstartPage(c *gin.Context) { var person Person if c.ShouldBind(&person) == nil { log.Println(person.Name) log.Println(person.Address) } c.String(200, "Success") }
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually. ^ SyntaxError: Unexpected token : at Object.exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:543:28) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Object.<anonymous> (C:\Users\nitin.mukesh\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32)
var exec = require('child_process').exec; exec('npm start', {windowsHide: true});
再次启动就不会出现控制台窗口了。
下面设置开机启动,可能会遇到第二个问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
pm2 save pm2 startup
[PM2][ERROR] Init system not found C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\API\Startup.js:209 throw new Error('Init system not found'); ^
Error: Init system not found at API.CLI.startup (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\API\Startup.js:209:13) at Command.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\binaries\CLI.js:707:9) at Command.listener (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:315:8) at Command.emit (events.js:315:20) at Command.parseArgs (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:651:12) at Command.parse (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:474:21) at Timeout._onTimeout (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\binaries\CLI.js:204:15) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7)
asp.net core在2.x版本中的方法是修改Startup类中的ConfigureServices方法,把返回值从void改成IServiceProvider并在方法结尾返回新的容器。然而在升级到3.1后,以前替换内置依赖容器的方法是不生效的。我们知道在dotnet core 3.x退出了一个新的通用主机。默认情况下我们新创建项目的启动方法配置了这个通用主机。
// Autofac使用ContainerBuilder public void ConfigureContainer(ContainerBuilder builder) { // Register your own things directly with Autofac, like: builder.RegisterModule(new MyApplicationModule()); }