Skip to content

✨ feat(oauth): Oauth2 #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ module github.com/hnit-acm/hfunc

go 1.14

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0

require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.2
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19
github.com/gin-gonic/gin v1.6.3
github.com/google/go-cmp v0.3.0 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect
google.golang.org/grpc v1.35.0
)
127 changes: 0 additions & 127 deletions go.sum

This file was deleted.

4 changes: 4 additions & 0 deletions oauth2/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package oauth2

func auth() {
}
58 changes: 58 additions & 0 deletions oauth2/ex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package oauth2

import (
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin"
"net/url"
)

type ClientDB struct {
store map[string]interface{}
}

func (c ClientDB) SetInfo(key string, val interface{}) error {
c.store[key] = val
return nil
}

func (c ClientDB) GetInfo(key string) (interface{}, error) {
v := c.store[key]
return v, nil
}

type TokenRedis struct {
store map[string]interface{}
}

func (t TokenRedis) SetInfo(key string, val interface{}) error {
t.store[key] = val
return nil
}

func (t TokenRedis) GetInfo(key string) (interface{}, error) {
v := t.store[key]
return v, nil
}

func (t TokenRedis) Refresh(key string, expire uint64) error {
t.store[key] = key
return nil
}

func (t TokenRedis) AccessTokenGenerate() string {
panic("implement me")
}

func ex() {
router := gin.Default()
router.Any("/authorize", func(c *gin.Context) {
session := sessions.Default(c)
inface := session.Get("ReturnUri")
var form url.Values
if val, ok := inface.(url.Values); ok {
form = val
}
session.Delete("ReturnUri")
session.Save()
})
}
4 changes: 4 additions & 0 deletions oauth2/oauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package oauth2

type Oauth2Func interface {
}
6 changes: 6 additions & 0 deletions oauth2/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package oauth2

type ClientStore interface {
SetInfo(key string, val interface{}) error
GetInfo(key string) (interface{}, error)
}
8 changes: 8 additions & 0 deletions oauth2/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package oauth2

type TokenStore interface {
SetInfo(key string, val interface{}) error
GetInfo(key string) (interface{}, error)
Refresh(key string, expire uint64) error
AccessTokenGenerate() string
}
51 changes: 51 additions & 0 deletions office/example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"fmt"
"github.com/hnit-acm/hfunc/office"
)

func main() {
excel, _ := office.OpenExcelFromFile("./test.xlsx")
sheet1 := excel.SelectSheet("Sheet1")
sheet1.SetRowWithMerged(office.UnitCell{
Col: "P",
Row: 1,
}, []interface{}{
"nieaowei", "123", "123wdas", "dsadqwewq", "dioasdoihasd",
})
sheet1.SetRowWithMerged(office.UnitCell{
Col: "P",
Row: 4,
}, []interface{}{
"nieaowei", "123", "123wdas", "dsadqwewq", "dioasdoihasd",
})
sheet1.SetRowWithMerged(office.UnitCell{
Col: "P",
Row: 7,
}, []interface{}{
"nieaowei", "123", "123wdas", "dsadqwewq", "dioasdoihasd",
})
sheet1.SetColWithMerged(office.UnitCell{
Col: "K",
Row: 1,
}, []interface{}{
"nieaowei", "123", "123wdas", "dsadqwewq", "dioasdoihasd",
})
sheet1.SetRowValueStartFrom(office.UnitCell{
Col: "L",
Row: 1,
}, [][]interface{}{
{"123", "123", "123"},
{"123", "123", "123"},
{"123", "123", "123"},
{"123", "123", "123"},
}, 3)
fmt.Println(sheet1.Search(office.SeatSignal, true))
fmt.Println(excel.SearchSheet("Sheet1", office.SeatSignal, true))
fmt.Println(sheet1.ParseN())
excel.SaveAs("./result.xlsx")
var e office.UnitCellIface = office.UnitCell{}
_, ok := e.(office.UnitCell)
fmt.Println(ok)
}
Binary file added office/example/result.xlsx
Binary file not shown.
Binary file added office/example/test.xlsx
Binary file not shown.
35 changes: 35 additions & 0 deletions office/excel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package office

import (
"github.com/360EntSecGroup-Skylar/excelize/v2"
"io"
)

type Excel struct {
*excelize.File
currentSheet string
}

// SelectSheet 选择工作表
func (e *Excel) SelectSheet(sheetName ...string) *SheetFunc {
e.currentSheet = e.GetSheetName(0)
for _, s := range sheetName {
e.currentSheet = s
}
f := SheetFunc{
e,
}
return &f
}

// OpenExcelFromFile 从文件读取excel
func OpenExcelFromFile(filename string) (*Excel, error) {
f, err := excelize.OpenFile(filename)
return &Excel{File: f}, err
}

// OpenExcelFromReader 从读取流读取excel
func OpenExcelFromReader(reader io.Reader) (*Excel, error) {
f, err := excelize.OpenReader(reader)
return &Excel{File: f}, err
}
58 changes: 58 additions & 0 deletions office/excel_mergedCell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package office

import "github.com/360EntSecGroup-Skylar/excelize/v2"

type MergedCellIface interface {
UnitCellIface
StartVal() UnitCellIface
EndVal() UnitCellIface
Val() interface{}
}

func IsMergedCell(cell UnitCellIface) (MergedCellIface, bool) {
val, ok := cell.(MergedCellIface)
return val, ok
}

type MergedCell struct {
Start UnitCellIface
End UnitCellIface
Value interface{}
}

func AxisToUnitCell(axis string) (UnitCell, error) {
col, row, err := excelize.SplitCellName(axis)
return UnitCell{
Col: col,
Row: row,
}, err
}

func (m MergedCell) StartVal() UnitCellIface {
return m.Start
}

func (m MergedCell) EndVal() UnitCellIface {
return m.End
}

func (m MergedCell) Val() interface{} {
return m.Value
}

func (m MergedCell) ColVal() string {
return m.StartVal().ColVal()
}

func (m MergedCell) RowVal() int {
return m.StartVal().RowVal()
}

//MergedIncludeUnit 该合并单元格是否包含某单元格
func MergedIncludeUnit(mergedCell MergedCellIface, cell UnitCellIface) bool {
if cell.ColVal() >= mergedCell.StartVal().ColVal() && cell.ColVal() <= mergedCell.EndVal().ColVal() &&
cell.RowVal() >= mergedCell.StartVal().RowVal() && cell.RowVal() <= mergedCell.EndVal().RowVal() {
return true
}
return false
}
Loading