gorm manytomany many2many use go program
type RoleHasPermissionList struct { model.Roles Rolehaspermissions []CUS_Rolehaspermissions `json:"rolehaspermissions" gorm:"foreignkey:role_id; references:id"` } type CUS_Rolehaspermissions struct { PermissionId int `json:"-"` RoleId int `json:"-"` PermissinInfo model.Permission `gorm:"foreignkey:id; references:permission_id"` } func (CUS_Rolehaspermissions) TableName() string { return "RoleHasPermissions" } type FormaterResult struct { model.Roles Permission []model.Permission `json:"permission"` } func GetRoleList(c *gin.Context) serializer.Response { var req GetRoleListRequest c.ShouldBind(&req) var total int64 var list []RoleHasPermissionList page := req.Page pageSize := req.PageSize model.DB. Scopes(util.Paginate(c, page, pageSize)). Preload("Rolehaspermissions.PermissinInfo"). Find(&list).Offset(-1).Limit(-1).Count(&total) // 重新整理輸出格式 var formater_result []FormaterResult for i, v := range list { formater_result = append(formater_result, FormaterResult{Roles: v.Roles}) for _, v2 := range v.Rolehaspermissions { formater_result[i].Permission = append(formater_result[i].Permission, v2.PermissinInfo) } } return serializer.Response{ Code: 0, Message: "成功", Data: util.Pagination(c, page, pageSize, total, formater_result), } } { "id": 1, "name": "company", "display_name": "公司", "guard_name": "admin_api", "created_at": "2020-03-26 14:34:25", "updated_at": "2020-03-26 14:34:25", "permission": [ { "id": 1, "name": "add company", "display_name": "add company", "guard_name": "admin_api", "created_at": "2020-03-26 14:34:25", "updated_at": "2020-03-26 14:34:25" }, { "id": 2, "name": "edit company", "display_name": "edit company", "guard_name": "admin_api", "created_at": "2020-03-26 14:34:25", "updated_at": "2020-03-26 14:34:25" }, ] }, ...
bytes32[] remix solidity
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract Fix { bytes32[] questionList= [ bytes32(0x52a6eb687cd22e80d3342eac6fcc7f2e19209e8f83eb9b82e81c6f3e6f30743b), bytes32(0x257f3de9149acf0a49d3f7668956aeb52490202fae9ec2e92c3caa7d5223c6ef) ]; // constructor() { // // questionList = [ // // bytes32(0x52a6eb687cd22e80d3342eac6fcc7f2e19209e8f83eb9b82e81c6f3e6f30743b), // // bytes32(0x257f3de9149acf0a49d3f7668956aeb52490202fae9ec2e92c3caa7d5223c6ef) // // ]; // } // function addQuestion(bytes32 questionKey) // public // returns(bool success) // { // questionList.push(questionKey); // return true; // } function getQuestionCount() public view returns(uint questionCount) { return questionList.length; } function getQuestionAtIndex(uint row) public view returns(bytes32 questionkey) { return questionList[row]; } }
[轉]After 5 years, I am out of the serverless compute cult
https://dev.to/brentmitchell/after-5-years-im-out-of-the-serverless-compute-cult-3f6d I have been using serverless computing and storage for nearly five years and I’m finally tired of it. I do feel like it has become a cult. In a cult, brainwashing is done so gradually, people have no idea it is going on. I feel like this has happened across the board with so many developers; many don’t even realize they are clouded. In my case, I took the serverless marketing and hype hook, line, and sinker for the first half of my serverless journey. After working with several companies small and large, I have been continually disappointed as our projects grew. The fact is, serverless technology is amazingly simple to start, but becomes a bear as projects and teams accelerate. A serverless project typically includes a fully serverless stack which can include (using a non-exhaustive list of AWS services): ...
jenkins withCredentials sshUserPrivateKey
https://codeleading.com/article/11015806881/. Remeber sshCommand remote, remote infos have identityFile. identityFile need be at insdie identity. Don’t understand identity be keep. Only can be used inside identity def getRemoteHost(ip, user) { def remote = [:] remote.name = ip remote.host = ip remote.user = user remote.identityFile = identity remote.port = 22 remote.allowAnyHosts = true return remote } pipeline { agent any environment { ssh_ip = 'ooo.xxx.ooo.xxx' ssh_user = 'ubuntu' ssh_jenkins_key_uid = 'oooooooo-xxxx-xxxx-xxxx-oooooooooooo' // SSH_CREDS = credentials('oooooooo-xxxx-xxxx-xxxx-oooooooooooo') } stages { stage('ssh Command'){ steps { withCredentials([sshUserPrivateKey(credentialsId: "${ssh_jenkins_key_uid}", keyFileVariable: 'identity')]) { sshCommand remote: getRemoteHost(ssh_ip, ssh_user), command: "echo" //在远程服务器执行echo命令 } } } } } def runCommand(cmd) { def remote = [:] remote.name = "${ssh_ip}" remote.host = "${ssh_ip}" remote.user = "${ssh_user}" // remote.identityFile = identity remote.port = 22 remote.allowAnyHosts = true withCredentials([sshUserPrivateKey( credentialsId: "${ssh_jenkins_key_uid}", keyFileVariable: 'identity')]) { remote.identityFile = identity sshCommand remote: remote, command: cmd } } pipeline { agent any environment { ssh_ip = 'ooo.xxx.ooo.xxx' ssh_user = 'ubuntu' ssh_jenkins_key_uid = 'oooooooo-xxxx-xxxx-xxxx-oooooooooooo' // SSH_CREDS = credentials('oooooooo-xxxx-xxxx-xxxx-oooooooooooo') } stages { stage('ssh Command') { steps { echo 'whoami start...' runCommand('whoami') echo 'whoami success' } } } }