Golang Gin Api become Windows Service Use github.com/kardianos/service
package main import ( "errors" "fmt" "io" "log" "net" "net/http" "os" "path/filepath" "strings" "time" "github.com/gin-gonic/gin" "github.com/joho/godotenv" "github.com/kardianos/service" ) // Process Windows Service // github.com/kardianos/service var logger service.Logger type program struct{} func (p *program) Start(s service.Service) error { // Start should not block. Do the actual work async. go p.run() return nil } func (p *program) Stop(s service.Service) error { // Stop should not block.
Modify ModelTrait file at \App\Traits
namespace App\Traits; trait ModelTrait { // fetaure Maybe belongsTo // get result but not effect this, keep this ORM status public function newSelfObject() { return $this->db->query($this->builder->getCompiledSelect(false)); } // copy self object return ORM Object public function cso() { $class_name = get_class($this); $class_new_object = (new $class_name); $class_new_object->builder = clone $this->builder; return $class_new_object; } public function hasOne($class, $relation_primary_key=null, $primary_key=null) { return $class->where($relation_primary_key ?? $this->primaryKey, $this->newSelfObject()->getRowArray()[$primary_key ?
https://localhost.run/docs/
Add ModelTrait file at \App\Traits
namespace App\Traits; trait ModelTrait { // fetaure Maybe belongsTo // get result but not effect this, keep this ORM status public function newSelfObject() { return $this->db->query($this->builder->getCompiledSelect(false)); } public function hasOne($class, $relation_primary_key=null, $primary_key=null) { return $class->where($relation_primary_key ?? $this->primaryKey, $this->newSelfObject()->getRowArray()[$primary_key ?? $this->primaryKey] ?? ''); } // whereIn If can't get records, return null. Usually use primaryKey cloud happen public function hasMany($class, $relation_primary_key=null, $primary_key=null) { $temp = array_column($this->newSelfObject()->getResult(), $primary_key ?
https://github.com/qianshou/SeckillSolution
https://blog.csdn.net/koastal/article/details/78995885
=====
https://blog.csdn.net/qq_38512763/article/details/118830903
https://codereview.stackexchange.com/questions/80080/aggregate-array-values-into-ranges
// Output: // Array ( // [0] => Array ( [0] => 1, [1] => 2, [2] => 3, [3] => 4, [4] => 5, [5] => 6 ) // [1] => Array ( [0] => 10, [1] => 11, [2] => 12, [3] => 13 ) // [2] => Array ( [0] => 20 ) // [3] => Array ( [0] => 24 ) // ) static function GetRanges1( $aNumbers ) { $aNumbers = array_unique( $aNumbers ); sort( $aNumbers ); $aGroups = array(); for( $i = 0; $i < count( $aNumbers ); $i++ ) { if( $i > 0 && ( $aNumbers[$i-1] == $aNumbers[$i] - 1 )) array_push( $aGroups[count($aGroups)-1], $aNumbers[$i] ); else array_push( $aGroups, array( $aNumbers[$i] )); } return $aGroups; } // Output: Array ( [0] => 1-6, [1] => 10-13, [2] => 20, [3] => 24 ) static function GetRanges2( $aNumbers ) { $aNumbers = array_unique( $aNumbers ); sort( $aNumbers ); $aGroups = array(); for( $i = 0; $i < count( $aNumbers ); $i++ ) { if( $i > 0 && ( $aNumbers[$i-1] == $aNumbers[$i] - 1 )) array_push( $aGroups[count($aGroups)-1], $aNumbers[$i] ); else array_push( $aGroups, array( $aNumbers[$i] )); } $aRanges = array(); foreach( $aGroups as $aGroup ) { if( count( $aGroup ) == 1 ) $aRanges[] = $aGroup[0]; else $aRanges[] = $aGroup[0] .