This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func AESEncrypt(key, text string) ([]byte, error) { | |
block, err := aes.NewCipher([]byte(key)) | |
if err != nil { | |
return nil, err | |
} | |
b := Base64Encode([]byte(text)) | |
ciphertext := make([]byte, aes.BlockSize+len(b)) | |
iv := ciphertext[:aes.BlockSize] | |
if _, err := io.ReadFull(rand.Reader, iv); err != nil { | |
return nil, err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func GetIPFromRequest(r *http.Request) string { | |
ip, _, err := net.SplitHostPort(r.RemoteAddr) | |
if err != nil { | |
glog.Errorf("userip: %q is not IP:port", r.RemoteAddr) | |
return "" | |
} | |
userIP := net.ParseIP(ip) | |
if userIP == nil { | |
glog.Errorf("userip: %q is not IP:port", r.RemoteAddr) | |
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func GetLocalIP() { | |
host, _ := os.Hostname() | |
addrs, _ := net.LookupIP(host) | |
for _, addr := range addrs { | |
if ipv4 := addr.To4(); ipv4 != nil { | |
//return ipv4.String() | |
} | |
} | |
//return "" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="back" style="position: fixed !important; background-position: center center; | |
position: absolute; top: 0; left: 0; height: 100%; width: 100%; z-index: 999; | |
background: #000 no-repeat center center; opacity: 0.8; filter: alpha(opacity=80); | |
font-size: 14px; line-height: 20px; display: none;"> | |
</div> | |
<div class="pop_winwrap" style="text-align: center; position: absolute; | |
top: 30%; left: 30%; margin: 20px 0 20px 0px; padding: 3px 3px 3px 10px; z-index: 1000; background: | |
opacity: 1.0; filter: alpha(opacity=100); display:none; "> | |
<img class='' id="" src="images/img.png" style="cursor: pointer;" /> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"fmt" | |
"log" | |
_ "github.com/denisenkom/go-mssqldb" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "gopkg.in/gomail.v2" | |
func main() { | |
m := gomail.NewMessage() | |
m.SetHeader("From", "[email protected]") | |
m.SetHeader("To", "[email protected]", "[email protected]") | |
m.SetAddressHeader("Cc", "[email protected]", "Dan") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net" | |
"os/exec" | |
"github.com/k0kubun/pp" | |
) | |
func Hosts(cidr string) ([]string, error) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool ExportExcel(Page page, string FileName, string SheetName, string ContentBody) | |
{ | |
try | |
{ | |
string content = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + SheetName + "</x:Name><x:WorksheetOptions><x:Print><x:ValidPrinterInfo /></x:Print></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>" + ContentBody + "</body></html>"; | |
page.Response.Buffer = true; | |
page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName + DateTime.Now.ToString("yyyyMMdd") + ".xls"); | |
page.Response.ContentEncoding = System.Text.Encoding.UTF8; | |
page.Response.ContentType = "application/vnd.ms-excel"; | |
page.EnableViewState = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 将DataTable数据导入到excel中 | |
/// </summary> | |
/// <param name="data">要导入的数据</param> | |
/// <param name="isColumnWritten">DataTable的列名是否要导入</param> | |
/// <param name="sheetName">要导入的excel的sheet的名称</param> | |
/// <returns>导入数据行数(包含列名那一行)</returns> | |
public int DataTableToExcel(DataTable data, string sheetName, bool isColumnWritten) | |
{ | |
int i = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 将excel中的数据导入到DataTable中 | |
/// </summary> | |
/// <param name="sheetName">excel工作薄sheet的名称</param> | |
/// <param name="isFirstRowColumn">第一行是否是DataTable的列名</param> | |
/// <returns>返回的DataTable</returns> | |
public DataTable ExcelToDataTable(string sheetName, bool isFirstRowColumn) | |
{ | |
ISheet sheet = null; | |
DataTable data = new DataTable(); |