Spring Boot File Download

spring boot application 提供下载的代码,可以返回一个Resource @RestController @RequiredArgsConstructor @RequestMapping("/api") public class ReportController { @GetMapping(value = "/filedownload") public ResponseEntity<InputStreamResource> downloadFile(HttpServletRequest request) { // ....................... // ....................... // ....................... ByteArrayInputStream stream = xxxxxx;// get the stream return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=file.xlsx") .body(new InputStreamResource(stream)); } }……

Continue reading

Azure AD SAML SSO with Node Application

Azure AD saml sso 代码 主要是参考文档 安装 passport-saml npm install passport-saml use passport passport.use(new SamlStrategy( { path: '/account/auth/blueid/callback', // 这个是callback需要稍后实现 entryPoint: '', // 这个是azure AD的一个配置, saml-based sso login url issuer: 'cobeedev', // basic saml configuration -> Identifier (Entity ID) cert: '', // refer later signatureAlgorithm: 'sha256' }, async function(profile, done) { // in this function, you can process profile to get necessary information console.log(profile); // lazy require const usersManagement = require('../../controllers/users/usersManagement'); const ssoUser = jsonUtil.profile2User(profile); let dbUser = await usersManagement.getUserByAzureMail(ssoUser.email); // if user was not found in db // process the scenario if (!dbUser) { await usersManagement.processAzureSSOUser(ssoUser); dbUser = await usersManagement.getUserByAzureMail(ssoUser.email); }……

Continue reading

Port Forwarding - Mac

Mac下端口转发 有时候要在本地起https,需要把443端口转发到8080或者其他的3000端口 ###设置转发 echo "rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 9443" | sudo pfctl -ef - 取消转发 sudo pfctl -s nat sudo pfctl -F all -f /etc/pf.conf……

Continue reading

Golang 中的零值

zero value (零值) 在golang中,零值会在很多地方隐式的用到,所以把零值列出来。 0 所有的integer类型 (int32/int64/…) 0.0 所有的float类型 (float32/float64/…) false boolean类型 "" string类型, 这点要特别注意,从java过来的开发人员容易认为 nil是把 string和nil比较, 应该 str == "" ,不是 str == nil nil interface, slices,……

Continue reading

Golang Panic 的时候通过defer更新返回值

在panic的函数中更新返回值 在golang中我们知道可以用defer, panic, recover来处理一些情况,比如,一般panic的话,如果在函数中没有处理,就会向上继续抛出 有时候,我们希望在出错的情况下,能够返回一个值。这个时候,defer就会比较好的处理这种情况。 func test() (r int) { defer func() { if……

Continue reading

Watson Assistant Easy Tool

Watson assistant 根据官方文档,已经提供了sdk, 自己的这个package只是使用 官方的sdk基础上,做了小小的封闭。代码托管在github上 watson 目前只有一个assitant package,提供方法来开始一个session并且发送message从而得到结果。 使用方法也比较简单,NewSessio……

Continue reading

Multiple Angular Material Table Sort

问题 在一个component里面,如果有多个mat-table matSort,怎么使用ViewChild 方案 使用ViewChild的时候,需要使用id @ViewChild('sort1') sort1: MatSort; 在页面中,需要 <mat-table #table [dataSource]="dataSource" #sort1="matSort" matSort>……

Continue reading

Angular Material Table Paginator ngIf

问题 一般来说,按angular material的官方文档, 在afterViewInit里面 可以把paginator或者sort和dataSource绑定在一起。但是如果这个table是在ngIf里面,也就是要在条件满足的情况下。这个时候的 @ViewChild(MatPaginator) paginator: MatPaginator; 可能就不好用了。因为还没有渲染,对应……

Continue reading

Go Download From Private Repo in Docker

问题 有时候开发的go project会用到一些私有仓库,或者自己搭的。比如用到了github.ibm.com里面的代码,如果在go.mod里面设置的 是github.ibm.com的网址的话,会发现build docker image的时候,提示access rights的问题。 方法 在你的Docke……

Continue reading

Go Gorm 操作数据库

Go/Gorm 操作 Postgres 虽然go提供了database/sql包来操作数据库,但是如果有个ORM的包,可以直接操作model来操作数据库,就像node里面的sequelize,是不是 也是挺好的。Gorm就实现了这个功能,这个包目前是github上star数最多的go orm包,包括中文资料,对小伙……

Continue reading